
Display Text and Images in Java Graphics 10.11
Example 10.7: Program to demonstrate JButton 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. JPanel panel = new DisplayPanel();
15. getContentPane().add(panel);
16. }
17. }
18. class DisplayPanel extends JPanel{
19. DisplayPanel() {
20. JButton button = new JButton(“Click ...