private static void constructMenu() { final JFrame lFrame = (JFrame) viewModel.get("window.frame"); final JMenuBar lMenuBar = new JMenuBar(); lFrame.setJMenuBar(lMenuBar); viewModel.put("menu", lMenuBar); final JMenu lFileMenu = new JMenu("File"); lFileMenu.setMnemonic(KeyEvent.VK_F); viewModel.put("menu.file", lFileMenu); lMenuBar.add(lFileMenu); final JMenuItem lExitItem = new JMenuItem((Action) viewModel.get("action.exit")); viewModel.put("menu.file.exit", lExitItem); lFileMenu.add(lExitItem); final JMenuItem lHelpMenu = new JMenu("Help"); lHelpMenu.setMnemonic(KeyEvent.VK_H); viewModel.put("menu.help", lHelpMenu); lMenuBar.add(lHelpMenu); final JMenuItem lHelpTopicsItem = new JMenuItem((Action) viewModel.get("action.help")); viewModel.put("menu.help.topics", lHelpTopicsItem); lHelpMenu.add(lHelpTopicsItem); final JMenuItem lAboutItem = new JMenuItem((Action) viewModel.get("action.about")); viewModel.put("menu.help.about", lAboutItem); lHelpMenu.add(lAboutItem); }
public static void main(String[] args) { constructResources(); constructFrame(); constructHelpSet(); constructActions(); constructMenu(); final JFrame lFrame = (JFrame) viewModel.get("window.frame"); lFrame.setVisible(true); }
private static void constructFrame() { final JFrame lFrame = new JFrame((String) viewModel.get("string.title")); lFrame.setIconImage((Image) viewModel.get("image.crab")); // Install the closing mechanism on the frame when the user // wants to close the frame by clicking the X button. lFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); lFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { final ExitAction lExitAction = (ExitAction) viewModel.get("action.exit"); if (lExitAction != null) { // If there is an exit action defined, we use this action. // It will have the same effect as calling the exit menu item. lExitAction.actionPerformed(new ActionEvent(lFrame, 0, "exit")); } else { // If the exit action is not available, we will close the frame anyhow. lFrame.dispose(); } } }); // Calculate the middle of the screen. final Rectangle lScreenRect = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration() .getBounds(); // Using the 'golden ratio' 1.618 for the width/height ratio. final Rectangle lFrameRect = new Rectangle(Math.min(647, lScreenRect.width), Math.min(400, lScreenRect.height)); // Set the window size and location. lFrame.setLocation( (lScreenRect.width - lFrameRect.width) / 2, (lScreenRect.height - lFrameRect.height) / 2); lFrame.setSize(lFrameRect.width, lFrameRect.height); viewModel.put("window.frame", lFrame); }