public class TopLevelDemoGUIApp
1: //TopLevelDemoGUIApp.java
3: import java.awt.*;
4: import java.awt.event.*;
5: import javax.swing.*;
8: public class TopLevelDemoGUIApp
9: {
10: private static void createAndShowGUI()
11: {
12: //Make sure we have nice window decorations.
13: JFrame.setDefaultLookAndFeelDecorated(true);
15: //Create and set up the window.
16: JFrame frame = new JFrame("TopLevelDemo");
17: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
19: //Create the menu bar. Make it have a cyan background.
20: JMenuBar cyanMenuBar = new JMenuBar();
21: cyanMenuBar.setOpaque(true);
22: cyanMenuBar.setBackground(Color.cyan);
23: cyanMenuBar.setPreferredSize(new Dimension(200, 20));
25: //Create a yellow label to put in the content pane.
26: JLabel yellowLabel = new JLabel();
27: yellowLabel.setOpaque(true);
28: yellowLabel.setBackground(Color.yellow);
29: yellowLabel.setPreferredSize(new Dimension(200, 180));
31: //Set the menu bar and add the label to the content pane.
32: frame.setJMenuBar(cyanMenuBar);
33: frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);
35: //Display the window.
36: frame.pack();
37: frame.setVisible(true);
38: }
40: public static void main(String[] args)
41: {
42: createAndShowGUI();
43: }
44: }