home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 2.7 KB | 124 lines |
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.event.*;
-
- public class Menu1 extends JPanel
- implements ActionListener, MenuListener
- {
- JTextField fldStatus;
-
- //Create the menu class
- public Menu1(JFrame frm)
- {
- JMenuBar bar = new JMenuBar();
- JMenu menu = new JMenu("Strategy");
- JMenuItem tmp;
-
- setBackground(Color.lightGray);
- setLayout(new BorderLayout());
-
- setDoubleBuffered(true);
-
- menu.addMenuListener(this);
-
- tmp = new JMenuItem("Lead");
- tmp.addActionListener(this);
- tmp.setActionCommand("Lead");
- menu.add(tmp);
-
- tmp = new JMenuItem("Follow");
- tmp.addActionListener(this);
- tmp.setActionCommand("Follow");
- menu.add(tmp);
-
- tmp = new JMenuItem("Resign");
- tmp.addActionListener(this);
- tmp.setActionCommand("Resign");
- menu.add(tmp);
-
- tmp = new JMenuItem("Quit");
- tmp.addActionListener(this);
- tmp.setActionCommand("Quit");
- menu.add(tmp);
-
- bar.add(menu);
-
- frm.setJMenuBar(bar);
-
- fldStatus = new JTextField(10);
- add(fldStatus,"South");
-
- }//constructor
-
- public void actionPerformed(ActionEvent e)
- {
- String cmd;
- cmd = e.getActionCommand();
-
- if (cmd.equals("Lead"))
- {
- fldStatus.setText("Action: Lead");
- }
- if (cmd.equals("Follow"))
- {
- fldStatus.setText("Action: Follow");
- }
- if (cmd.equals("Resign"))
- {
- fldStatus.setText("Action: Resign");
- }
- if (cmd.equals("Quit"))
- {
- System.exit(0);
- }
-
- }
-
- public void menuSelected(MenuEvent e)
- {
- fldStatus.setText("Menu Selected");
- }
-
- public void menuDeselected(MenuEvent e)
- {
- fldStatus.setText("Menu Deselected");
- }
-
- public void menuCanceled(MenuEvent e)
- {
- fldStatus.setText("Menu Cancelled");
- }
-
- public static void main(String s[])
- {
- JFrame f = new JFrame("Menu1");
- Menu1 panel = new Menu1(f);
-
- f.setForeground(Color.black);
- f.setBackground(Color.lightGray);
- f.getContentPane().add(panel, "Center");
-
- f.setSize(300,200);
- f.setVisible(true);
- f.addWindowListener(new WindowCloser());
-
-
- }//main
-
-
- }//class
-
- //close down gracefully
- class WindowCloser extends WindowAdapter
- {
- public void windowClosing(WindowEvent e)
- {
- Window win = e.getWindow();
- win.setVisible(false);
- win.dispose();
- System.exit(0);
- }//windowClosing
- }//class WindowCloser
-
-