intermediate/GUIExample

From ggc

Jump to: navigation, search

01 package intermediate;
02 
03 import java.awt.FlowLayout;
04 import java.awt.event.ActionEvent;
05 import java.awt.event.ActionListener;
06 
07 import javax.swing.*;
08 
09 public class GUIExample
10 {
11   private JFrame frame;
12   private JButton button;
13   private JTextArea text;
14 
15   public GUIExample()
16   {
17     frame=new JFrame("My simple window");
18     frame.setVisible(true);
19     button=new JButton("Click me");
20     text=new JTextArea(1040);
21     frame.getContentPane().setLayout(new FlowLayout());
22     frame.getContentPane().add(button);
23     frame.getContentPane().add(new JScrollPane(text));
24     button.addActionListener(new React2());
25     frame.pack();
26   }
27 
28   class React2 implements ActionListener
29   {
30 
31     public void actionPerformed(ActionEvent e)
32     {
33       text.append("Clicked");
34     }
35 
36   }
37 
38 
39   /**
40    @param args
41    */
42   public static void main(String[] args)
43   {
44     //other inner class
45     GUIExample example=new GUIExample();
46 
47     /*JFrame frame=new JFrame("My simple window");
48     frame.setVisible(true);
49     JButton button=new JButton("Click me");
50     final JTextArea text=new JTextArea(10, 40);
51     frame.getContentPane().setLayout(new FlowLayout());
52     frame.getContentPane().add(button);
53     frame.getContentPane().add(new JScrollPane(text));
54     frame.pack();
55 
56     //inner class version
57     class React implements ActionListener
58     {
59 
60       public void actionPerformed(ActionEvent e) 
61       {
62         text.append("Clicked");        
63       }
64       
65   }
66 
67     button.addActionListener(new React());
68     */
69     //anonymous class version
70     /*button.addActionListener(
71         new ActionListener()
72         {
73           public void actionPerformed(ActionEvent arg0) {
74             text.append("Clicked");
75             
76           }
77         });*/
78   }
79 
80 }


Download/View intermediate/GUIExample.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter