Java Reference
In-Depth Information
Display 17.14
A GUI with a Menu (part 1 of 3)
1 import javax.swing.JFrame;
2 import javax.swing.JPanel;
3 import java.awt.GridLayout;
4 Import java.awt.Color;
5 import javax.swing.JMenu;
6 import javax.swing.JMenuItem;
7 import javax.swing.JMenuBar;
8 import java.awt.event.ActionListener;
9 import java.awt.event.ActionEvent;
10 public class MenuDemo extends JFrame implements ActionListener
11 {
12
public static final int WIDTH = 300;
13
public static final int HEIGHT = 200;
14
private JPanel bluePanel;
15
private JPanel whitePanel;
16
private JPanel grayPanel;
17 public static void main(String[] args)
18 {
19 MenuDemo gui = new MenuDemo();
20 gui.setVisible( true );
21 }
22 public MenuDemo()
23 {
24 super ("Menu Demonstration");
25 setSize(WIDTH, HEIGHT);
26 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
27 setLayout( new GridLayout(1, 3));
28 bluePanel = new JPanel();
29 bluePanel.setBackground(Color.LIGHT_GRAY);
30 add(bluePanel);
31 whitePanel = new JPanel();
32 whitePanel.setBackground(Color.LIGHT_GRAY);
33 add(whitePanel);
34 grayPanel = new JPanel();
Search WWH ::




Custom Search