]> git.argeo.org Git - gpl/argeo-slc.git/blob - sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/ui/SwingTestUi.java
91dfd126e03759c51ba5b9c1847789c1add02ce8
[gpl/argeo-slc.git] / sandbox / argeo.slc.jemmytest / src / main / java / org / argeo / slc / jemmytest / ui / SwingTestUi.java
1 package org.argeo.slc.jemmytest.ui;
2
3 import java.awt.GridLayout;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6
7 import javax.swing.JButton;
8 import javax.swing.JFrame;
9 import javax.swing.JLabel;
10
11 public class SwingTestUi {
12 private static void createAndShowGUI(boolean exitOnClose) {
13 // Create and set up the window.
14 JFrame frame = new JFrame("HelloWorldSwing");
15 if (exitOnClose)
16 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
17
18 frame.getContentPane().setLayout(new GridLayout(2, 1));
19
20 // Add the ubiquitous "Hello World" label.
21 final JLabel label = new JLabel("Hello World");
22 frame.getContentPane().add(label);
23
24 final JButton button = new JButton("Button");
25 frame.getContentPane().add(button);
26 button.addActionListener(new ActionListener() {
27 public void actionPerformed(ActionEvent e) {
28 label.setText("Pressed!!");
29 }
30 });
31
32 // Display the window.
33 frame.pack();
34 frame.setVisible(true);
35 }
36
37 public static void main(String[] args) {
38 boolean noExitOnClose = false;
39 for (int i = 0; i < args.length; i++) {
40 if (args[i].equals("noExitOnClose")) {
41 noExitOnClose = true;
42 }
43 }
44
45 final boolean exitOnClose = !noExitOnClose;
46 javax.swing.SwingUtilities.invokeLater(new Runnable() {
47 public void run() {
48 createAndShowGUI(exitOnClose);
49 }
50 });
51 }
52
53 }