📄 hotelframe.java
字号:
package ui;import core.*;import java.util.*;import javax.swing.*;import java.awt.event.*;public class HotelFrame extends JFrame{ private CommandMap m_commands; private boolean m_closed; public HotelFrame () { super ("Hotel Reservation Management"); m_commands = new CommandMap (); setupMenus (); addWindowListener(new WindowAdapter() { public void windowClosed (WindowEvent e) { synchronized (HotelFrame.this) { m_closed = true; HotelFrame.this.notify(); } } }); setDefaultCloseOperation(DISPOSE_ON_CLOSE); pack(); show(); } private void setupMenus () { JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu file = new JMenu ("File"); JMenuItem exitItem = new JMenuItem ("Exit"); exitItem.addActionListener (createCommandListener ("exit")); file.add (exitItem); JMenu help = new JMenu ("Help"); JMenuItem helpItem = new JMenuItem ("Help..."); helpItem.addActionListener (createCommandListener ("help")); help.add (helpItem); JMenu command = new JMenu ("Commands"); Collection commands = m_commands.values(); for (Iterator iter = commands.iterator(); iter.hasNext(); ) { Command cmd = (Command) iter.next(); String cmdName = cmd.getName (); String menuName = cmd.getMenuName (); if (!(cmdName.equalsIgnoreCase("exit") || cmdName.equalsIgnoreCase("help") || cmdName.equalsIgnoreCase("_unknown"))) { JMenuItem cmdItem = new JMenuItem (menuName); cmdItem.addActionListener (createCommandListener(cmdName)); command.add (cmdItem); } } // add other commands here menuBar.add (file); menuBar.add (command); menuBar.add (help); } CommandMap getCommands () { return m_commands; } private CommandListener createCommandListener (String name) { return new CommandListener (this, name); } /** allows a thread to wait for this window to close */ public synchronized void waitForClose () { while (! m_closed) try { wait(); } catch (InterruptedException e) { } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -