/* Assignment 8 */ /* The three colors */ /* Author: Carsten Schuermann */ /* Date: Wed Mar 22 13:37:57 2006 */ import java.awt.*; import java.awt.event.*; import java.text.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; import java.util.*; public class TheThreeColors extends JFrame { JDesktopPane desktop; public TheThreeColors() { super("TheThreeColors"); int inset = 50; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(inset, inset, screenSize.width - inset*2, screenSize.height - inset*2); desktop = new JDesktopPane(); desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); createFrame(); setContentPane(desktop); setJMenuBar(createMenuBar()); } protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Document"); menu.setMnemonic(KeyEvent.VK_D); menuBar.add(menu); //Set up the first menu item. JMenuItem menuItem = new JMenuItem("ComboBox"); menuItem.setMnemonic(KeyEvent.VK_C); menuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_C, ActionEvent.ALT_MASK)); menuItem.addActionListener( new ActionListener(){ public void actionPerformed (ActionEvent e){ createFrame (); } }); menu.add(menuItem); //Set up the second menu item. menuItem = new JMenuItem("JRadioButton"); menuItem.setMnemonic(KeyEvent.VK_J); menuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_J, ActionEvent.ALT_MASK)); menuItem.addActionListener( new ActionListener(){ public void actionPerformed (ActionEvent e){ createButtonFrame (); } }); menu.add(menuItem); //Set up the third menu item. menuItem = new JMenuItem("Color"); menuItem.setMnemonic(KeyEvent.VK_O); menuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.ALT_MASK)); menuItem.addActionListener( new ActionListener(){ public void actionPerformed (ActionEvent e){ createColorFrame (); } }); menu.add(menuItem); //Set up the fourth menu item. menuItem = new JMenuItem("Quit"); menuItem.setMnemonic(KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.ALT_MASK)); menuItem.addActionListener( new ActionListener(){ public void actionPerformed (ActionEvent e){ System.exit (1); } }); menu.add(menuItem); return menuBar; } //Create a new drop down frame. protected void createFrame() { } //Create a new radio Button frame. protected void createButtonFrame() { } //Create a new color frame. protected void createColorFrame() { } //Quit the application. protected void quit() { System.exit(0); } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. TheThreeColors frame = new TheThreeColors(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Display the window. frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }