
10.6 Graphics Using Swing Components
10. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
11. setTitle(“Swing Demo”);
12. setSize(300, 150);
13. setLocation(100,100);
14. JPanel panel = new DisplayPanel();
15. getContentPane().add(panel);
16. }
17. }
18. class DisplayPanel extends JPanel{
19. DisplayPanel() {
20. //Widgets will be added here
21. }
22. }
The code of Example 10.3 is almost similar to Example 10.2. The output shown is also the
same. In the preceding example, we instantiate the DisplayPanel object in line 14. The
constructor for DisplayPanel is presently empty, but going forward as we will see in
subsequent examples all the widget ...