Advertisement
Guest User

Untitled

a guest
Dec 25th, 2011
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package main;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.KeyEvent;
  6. import javax.swing.JFrame;
  7. import javax.swing.JMenu;
  8. import javax.swing.JMenuBar;
  9. import javax.swing.JMenuItem;
  10.  
  11. public class Main {
  12.     public static void main(String args[]) {
  13.         Main a = new Main();
  14.         a.Run();
  15.     }
  16.    
  17.     private void Run() {
  18.         JFrame frame = new JFrame("Name");
  19.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20.         frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
  21.         frame.setVisible(true);
  22.        
  23.         JMenuBar menuBar;
  24.         JMenu fileMenu;
  25.         JMenuItem fileMenuExit;
  26.        
  27.         menuBar = new JMenuBar();
  28.         fileMenu = new JMenu("File");
  29.         fileMenu.setMnemonic(KeyEvent.VK_F);
  30.         menuBar.add(fileMenu);
  31.         fileMenuExit = new JMenuItem("Exit");
  32.         fileMenuExit.setActionCommand("menu-file-exit");
  33.         fileMenuExit.addActionListener(new AL());
  34.         fileMenu.add(fileMenuExit);
  35.        
  36.         frame.setJMenuBar(menuBar);
  37.     }
  38.    
  39.     private class AL implements ActionListener {
  40.         public void actionPerformed(ActionEvent e) {
  41.             if ("menu-file-exit".equals(e.getActionCommand())) {
  42.                 // prompt about exiting
  43.                 // if (!saved)
  44.                 System.exit(0);
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement