protected void assembleSystemMenu() { systemMenu = new JPopupMenu(); JMenuItem mi = (JMenuItem) systemMenu.add(new JMenuItem(restoreAction)); mi.setMnemonic('R'); mi = (JMenuItem) systemMenu.add(new JMenuItem(moveAction)); mi.setMnemonic('M'); mi = (JMenuItem) systemMenu.add(new JMenuItem(sizeAction)); mi.setMnemonic('S'); mi = (JMenuItem) systemMenu.add(new JMenuItem(iconifyAction)); mi.setMnemonic('n'); mi = (JMenuItem) systemMenu.add(new JMenuItem(maximizeAction)); mi.setMnemonic('x'); systemMenu.add(new JSeparator()); mi = (JMenuItem) systemMenu.add(new JMenuItem(closeAction)); mi.setMnemonic('C'); systemButton = new SystemButton(); systemButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { systemMenu.show(systemButton, 0, BUTTON_SIZE); } }); systemButton.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent evt) { try { frame.setSelected(true); } catch (PropertyVetoException pve) { } if ((evt.getClickCount() == 2)) { closeAction.actionPerformed( new ActionEvent( evt.getSource(), ActionEvent.ACTION_PERFORMED, null, evt.getWhen(), 0)); systemMenu.setVisible(false); } } }); }
public void layoutContainer(Container c) { int w = getWidth(); systemButton.setBounds(0, 0, BUTTON_SIZE, BUTTON_SIZE); int x = w - BUTTON_SIZE; if (frame.isMaximizable()) { maximizeButton.setBounds(x, 0, BUTTON_SIZE, BUTTON_SIZE); x -= BUTTON_SIZE; } else if (maximizeButton.getParent() != null) { maximizeButton.getParent().remove(maximizeButton); } if (frame.isIconifiable()) { minimizeButton.setBounds(x, 0, BUTTON_SIZE, BUTTON_SIZE); x -= BUTTON_SIZE; } else if (minimizeButton.getParent() != null) { minimizeButton.getParent().remove(minimizeButton); } title.setBounds(BUTTON_SIZE, 0, x, BUTTON_SIZE); }