Posted By

nickmeinhold on 10/03/08


Tagged


Versions (?)

NickMeinholdMenuBar v0.2


 / Published in: Java
 

  1. /* Last Update: 28 Sept 08 - 1750 hrs */
  2.  
  3. package project;
  4.  
  5. import java.awt.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.KeyEvent;
  8.  
  9. import javax.swing.*;
  10.  
  11. public class MenuBar extends JMenuBar {
  12.  
  13. // image sizes are all 40 pixels (width) by 35 pixels (height)
  14.  
  15. MenuBar() {
  16.  
  17. JMenuItem menuItem;
  18. JMenu menu;
  19. JCheckBoxMenuItem cbMenuItem;
  20.  
  21. this.setOpaque(true);
  22. this.setBackground(new Color(154, 165, 127));
  23. this.setPreferredSize(new Dimension(200, 20));
  24.  
  25. menu = new JMenu("File");
  26. menu.setMnemonic(KeyEvent.VK_F);
  27.  
  28. menuItem = new JMenuItem("Create New Map", new ImageIcon("images/menu/newmap.png"));
  29. menuItem.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
  30. menu.add(menuItem);
  31.  
  32. menuItem = new JMenuItem("Open Map", new ImageIcon("images/menu/open.png"));
  33. menuItem.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
  34. menu.add(menuItem);
  35.  
  36. menu.addSeparator();
  37.  
  38. menuItem = new JMenuItem("Save", new ImageIcon("images/menu/save.png"));
  39. menuItem.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
  40. menu.add(menuItem);
  41.  
  42. menuItem = new JMenuItem("Save As...", new ImageIcon("images/menu/saveas.png"));
  43. menu.add(menuItem);
  44.  
  45. menu.addSeparator();
  46.  
  47. menuItem = new JMenuItem("Print", new ImageIcon("images/menu/print.png"));
  48. menuItem.setAccelerator(KeyStroke.getKeyStroke('P', Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
  49. menu.add(menuItem);
  50.  
  51. menuItem = new JMenuItem("Close", new ImageIcon("images/menu/close.png"));
  52. menuItem.setAccelerator(KeyStroke.getKeyStroke('C', Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
  53. menu.add(menuItem);
  54.  
  55. menu.addSeparator();
  56.  
  57. menuItem = new JMenuItem("Exit", new ImageIcon("images/menu/exit.png"));
  58. menuItem.setAccelerator(KeyStroke.getKeyStroke('X', Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
  59. menuItem.addActionListener(new ExitSelected());
  60. menu.add(menuItem);
  61.  
  62.  
  63. this.add(menu);
  64.  
  65. menu = new JMenu("Edit");
  66. menu.setMnemonic(KeyEvent.VK_E);
  67.  
  68. menuItem = new JMenuItem("Open", new ImageIcon("images/menu/open.png"));
  69. menuItem.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
  70. menu.add(menuItem);
  71.  
  72. this.add(menu);
  73.  
  74. menu = new JMenu("View");
  75. menu.setMnemonic(KeyEvent.VK_V);
  76.  
  77. cbMenuItem = new JCheckBoxMenuItem("All", true);
  78. menu.add(cbMenuItem);
  79.  
  80. cbMenuItem = new JCheckBoxMenuItem("Trees");
  81. menu.add(cbMenuItem);
  82.  
  83. cbMenuItem = new JCheckBoxMenuItem("Signs");
  84. menu.add(cbMenuItem);
  85.  
  86. cbMenuItem = new JCheckBoxMenuItem("Buildings");
  87. menu.add(cbMenuItem);
  88.  
  89. this.add(menu);
  90.  
  91. menu = new JMenu("Help");
  92. menu.setMnemonic(KeyEvent.VK_H);
  93.  
  94. //a group of JMenuItems
  95. menuItem = new JMenuItem("Open", new ImageIcon("images/menu/open.png"));
  96. menuItem.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
  97. menu.add(menuItem);
  98.  
  99. this.add(menu);
  100.  
  101.  
  102.  
  103. }
  104. }

Report this snippet  

You need to login to post a comment.