1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
/**
* Program: Second.java - Customizes a subclass of JPanel //Note 1
* @version 2003-00-00
* @author Mickey Mouse
*/
import java.awt.*; //Note 2
import javax.swing.*;
/////////////////////////////////////////////////////////// class Second
class Second {
//====================================================== method main
public static void main(String[] args) {
JFrame myWindow = new JFrame("SecondWindow");
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Note 3
myWindow.getContentPane().add(new SecondPanel()); //Note 4
myWindow.pack(); // finalize the layout //Note 5
myWindow.show(); // make window visible
}//end main
}//endclass Second
////////////////////////////////////////////////////// class SecondPanel
class SecondPanel extends JPanel { //Note 6
//====================================================== constructor
SecondPanel() { //Note 7
//--- create the components
JButton helloButton; //Note 8
helloButton = new JButton("Hello Earthlings."); //Note 9
//Note 10
this.setLayout(new FlowLayout()); //Note 11
this.add(helloButton); //Note 12
}//end constructor
}//endclass Secondpanel
The text from the above example can be selected, copied, and pasted into an editor.
|