
Exploring the Swing Components 10.5
Example 10.2: Program to demonstrate JFrame class
1. import javax.swing.*;
2. public class SwingDemo {
3. public static void main(String[] args) {
4. JFrame frame = new DisplayFrame();
5. frame.setVisible(true);
6. }
7. }
8. class DisplayFrame extends JFrame{
9. DisplayFrame(){
10. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
11. setTitle(“Swing Demo”);
12. setSize(300, 150);
13. setLocation(100,100);
14. }
15. }
The JFrame class is present in javax.swing.JFrame. To use this class, we use the
import statement import javax.swing.* as shown in line 1. In line 4, we instantiate the
DisplayFrame ...