From ggc
|
01 packagepackage is used to name the directory or folder a class is in intermediate;
02
03 importimport means to make the classes and/or packages available in this program java.awt.FlowLayout;
04 importimport means to make the classes and/or packages available in this program java.awt.event.ActionEvent;
05 importimport means to make the classes and/or packages available in this program java.awt.event.ActionListener;
06
07 importimport means to make the classes and/or packages available in this program javax.swing.*;
08
09 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects GUIExample
10 {open braces start code blocks and must be matched with a close brace
11 privateprivate is used to restrict access to the current class only JFrame frame;
12 privateprivate is used to restrict access to the current class only JButton button;
13 privateprivate is used to restrict access to the current class only JTextArea text;
14
15 publicpublic is used to indicate unrestricted access (any other class can have access) GUIExample()
16 {open braces start code blocks and must be matched with a close brace
17 frame=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor JFrame("My simple window");
18 frame.setVisible(truetrue is the boolean value that is the opposite of false);
19 button=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor JButton("Click me");
20 text=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor JTextArea(10, 40);
21 frame.getContentPane().setLayout(newnew is used to create objects by calling the constructor FlowLayout());
22 frame.getContentPane().add(button);
23 frame.getContentPane().add(newnew is used to create objects by calling the constructor JScrollPane(text));
24 button.addActionListener(newnew is used to create objects by calling the constructor React2());
25 frame.pack();
26 }close braces end code blocks and must match an earlier open brace
27
28 classclass is a group of fields and methods used for making objects React2 implementsimplements means providing method bodies for the methods declared in the corresponding interface ActionListener
29 {open braces start code blocks and must be matched with a close brace
30
31 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value actionPerformed(ActionEvent e)
32 {open braces start code blocks and must be matched with a close brace
33 text.append("Clicked");
34 }close braces end code blocks and must match an earlier open brace
35
36 }close braces end code blocks and must match an earlier open brace
37
38
39 /**
40 * @paramnull args
41 */
42 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args)
43 {open braces start code blocks and must be matched with a close brace
44 //other inner class
45 GUIExample example=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor GUIExample();
46
47 /*JFrame frame=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor JFrame("My simple window");
48 frame.setVisible(truetrue is the boolean value that is the opposite of false);
49 JButton button=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor JButton("Click me");
50 finalfinal means not changeable (often used for constants) JTextArea text=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor JTextArea(10, 40);
51 frame.getContentPane().setLayout(newnew is used to create objects by calling the constructor FlowLayout());
52 frame.getContentPane().add(button);
53 frame.getContentPane().add(newnew is used to create objects by calling the constructor JScrollPane(text));
54 frame.pack();
55
56 //inner class version
57 classclass is a group of fields and methods used for making objects React implementsimplements means providing method bodies for the methods declared in the corresponding interface ActionListener
58 {open braces start code blocks and must be matched with a close brace
59
60 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value actionPerformed(ActionEvent e)
61 {open braces start code blocks and must be matched with a close brace
62 text.append("Clicked");
63 }close braces end code blocks and must match an earlier open brace
64
65 }close braces end code blocks and must match an earlier open brace
66
67 button.addActionListener(newnew is used to create objects by calling the constructor React());
68 */
69 //anonymous class version
70 /*button.addActionListener(
71 newnew is used to create objects by calling the constructor ActionListener()
72 {open braces start code blocks and must be matched with a close brace
73 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value actionPerformed(ActionEvent arg0) {open braces start code blocks and must be matched with a close brace
74 text.append("Clicked");
75
76 }close braces end code blocks and must match an earlier open brace
77 }close braces end code blocks and must match an earlier open brace);*/
78 }close braces end code blocks and must match an earlier open brace
79
80 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/GUIExample.java