]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - sandbox/argeo.slc.testui/src/main/java/org/argeo/slc/testui/SwingTestUi.java
Detached UI architecture
[gpl/argeo-slc.git] / sandbox / argeo.slc.testui / src / main / java / org / argeo / slc / testui / SwingTestUi.java
index 4ff18c746edc6e802553bc028708870b08c52aff..de3f6ad957cfc5193088d28e92c299b1c15fe02e 100644 (file)
@@ -5,29 +5,70 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
 import javax.swing.JButton;
+import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
 
 public class SwingTestUi {
        private static void createAndShowGUI(boolean exitOnClose) {
                // Create and set up the window.
-               JFrame frame = new JFrame("HelloWorldSwing");
+               final JFrame frame = new JFrame("HelloWorldSwing");
                if (exitOnClose)
                        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
-               frame.getContentPane().setLayout(new GridLayout(2, 1));
+               frame.getContentPane().setLayout(new GridLayout(4, 1));
 
-               // Add the ubiquitous "Hello World" label.
+               // "Hello World" label.
                final JLabel label = new JLabel("Hello World");
                frame.getContentPane().add(label);
 
-               final JButton button = new JButton("Button");
-               frame.getContentPane().add(button);
-               button.addActionListener(new ActionListener() {
-                       public void actionPerformed(ActionEvent e) {
-                               label.setText("Pressed!!");
-                       }
-               });
+               // Change label button
+               {
+                       final JButton button = new JButton("Button");
+                       frame.getContentPane().add(button);
+                       button.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       if (label.getText().equals("Hello World"))
+                                               label.setText("Pressed!!");
+                                       else
+                                               label.setText("Hello World");
+                               }
+                       });
+               }
+
+               // Start dialog button
+               {
+                       final JButton buttonStart = new JButton("Start");
+                       frame.getContentPane().add(buttonStart);
+                       buttonStart.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       JDialog dialog = new JDialog(frame, "TestDialog");
+                                       JLabel label = new JLabel("Dialog open");
+                                       dialog.getContentPane().add(label);
+                                       dialog.pack();
+                                       dialog.setVisible(true);
+                               }
+                       });
+               }
+
+               // Complex Panel
+               {
+                       JPanel complexPanel = new JPanel();
+                       complexPanel.setLayout(new GridLayout(1, 2));
+                       final JTextField textTime = new JTextField(Long.toString(System
+                                       .currentTimeMillis()));
+                       complexPanel.add(textTime);
+                       JButton buttonTime = new JButton("Now!");
+                       buttonTime.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       textTime.setText(Long.toString(System.currentTimeMillis()));
+                               }
+                       });
+                       complexPanel.add(buttonTime);
+                       frame.getContentPane().add(complexPanel);
+               }
 
                // Display the window.
                frame.pack();