PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/src/AForceMenu.java

http://airforce2.googlecode.com/
Java | 729 lines | 496 code | 167 blank | 66 comment | 72 complexity | 556ccf06d64d9ac503aa3e1b9f51a2fd MD5 | raw file
  1. // AForceMenu.java
  2. // Jim Sproch
  3. // Created: April 29, 2006
  4. // Modified: March 30, 2008
  5. // Part of the Aforce Port
  6. // Mac < Windows < Linux
  7. /**
  8. AForceMenu is the top menu bar at the top of the AForce window!
  9. @author Jim Sproch
  10. @version 0.1a beta
  11. */
  12. import java.awt.*;
  13. import java.awt.event.*;
  14. import javax.swing.*;
  15. import javax.swing.text.*;
  16. import javax.swing.event.*;
  17. import java.text.BreakIterator;
  18. import java.lang.reflect.Method; //Needed for opening web browser
  19. public class AForceMenu implements ActionListener
  20. {
  21. private final int ITEM_PLAIN = 0; // Item types
  22. private final int ITEM_CHECK = 1;
  23. private final int ITEM_RADIO = 2;
  24. private static AForce aforce;
  25. JPanel topPanel;
  26. JMenuBar menuBar;
  27. JMenu menuGame;
  28. JMenu menuGameNewGame;
  29. JMenuItem menuGameNewGameSingle;
  30. JMenuItem menuGameNewGameMulti;
  31. JMenuItem menuGameNewGameCustom;
  32. JMenuItem menuGameNew;
  33. JMenuItem menuGamePauseResume;
  34. JMenuItem menuGameScores;
  35. JMenuItem menuGameOpen;
  36. JMenuItem menuGameScreenShot;
  37. JMenuItem menuGameSave;
  38. JMenuItem menuGameSaveAs;
  39. JMenuItem menuGameExit;
  40. JMenu menuOptions;
  41. JMenuItem menuOptionsSingle;
  42. JMenuItem menuOptionsMulti;
  43. JMenu menuHelp;
  44. JMenuItem menuHelpHandbook;
  45. JMenuItem menuHelpTipoftheDay;
  46. JMenuItem menuHelpBugReport;
  47. JMenuItem menuHelpDonate;
  48. JMenuItem menuHelpAbout;
  49. public AForceMenu(Display frame, final AForce owner)
  50. {
  51. aforce = owner;
  52. // Create the menu bar
  53. menuBar = new JMenuBar();
  54. // Set this instance as the application's menu bar
  55. frame.setJMenuBar(menuBar);
  56. // Build the property sub-menu
  57. menuGameNewGame = new JMenu("New");
  58. menuGameNewGame.setMnemonic('N');
  59. // Create property items
  60. menuGameNewGameSingle = CreateMenuItem( menuGameNewGame, ITEM_PLAIN, "Single-Player Game", null, 'S', null, AForceMenu.Identification.NewSinglePlayerGame);
  61. menuGameNewGameMulti = CreateMenuItem( menuGameNewGame, ITEM_PLAIN, "Multi-Player Game", null, 'M', null, AForceMenu.Identification.NewMultiPlayerGame);
  62. menuGameNewGameCustom = CreateMenuItem( menuGameNewGame, ITEM_PLAIN, "Custom (Requires Root)", null, 'C', null, AForceMenu.Identification.NewCustomGame);
  63. // Create the file menu
  64. menuGame = new JMenu("Game");
  65. menuGame.setMnemonic('G');
  66. menuBar.add(menuGame);
  67. menuGame.add(menuGameNewGame);
  68. menuGamePauseResume = CreateMenuItem(menuGame, ITEM_PLAIN, "Pause/Resume", null, 'r', "Pause/Resume Game", AForceMenu.Identification.PauseResume);
  69. menuGamePauseResume = CreateMenuItem(menuGame, ITEM_PLAIN, "High Scores", null, 'r', "High Score List", AForceMenu.Identification.HighScores);
  70. menuGameScreenShot = CreateMenuItem(menuGame, ITEM_PLAIN, "Capture ScreenShot", null, 'c', "Capture ScreenShot", AForceMenu.Identification.ScreenShot);
  71. menuGameSave = CreateMenuItem(menuGame, ITEM_PLAIN, "Save", null, 's', "Save", AForceMenu.Identification.Save);
  72. menuGameSaveAs = CreateMenuItem(menuGame, ITEM_PLAIN, "Save As", null, 'a', "Save As", AForceMenu.Identification.SaveAs);
  73. menuGameExit = CreateMenuItem(menuGame, ITEM_PLAIN, "Exit", null, 'x', "Exit the program", AForceMenu.Identification.EXIT);
  74. // Create the Options menu
  75. menuOptions = new JMenu("Options");
  76. menuOptions.setMnemonic('O');
  77. menuBar.add(menuOptions);
  78. // Create edit menu options
  79. menuOptionsSingle = CreateMenuItem(menuOptions, ITEM_PLAIN, "Single-Player Options", null, 'S', "Options for single-player games", AForceMenu.Identification.SinglePlayerOptions);
  80. menuOptionsMulti = CreateMenuItem(menuOptions, ITEM_PLAIN, "Multi-Player Options", null, 'M', "Options for multi-player lan games", AForceMenu.Identification.MultiPlayerOptions);
  81. // Create the Help menu
  82. menuHelp = new JMenu("Help");
  83. menuHelp.setMnemonic('H');
  84. menuBar.add(menuHelp);
  85. // Create edit menu options
  86. menuHelpHandbook = CreateMenuItem( menuHelp, ITEM_PLAIN, "AForce Handbook", null, 'H', "AForce Handbook", AForceMenu.Identification.HelpHandbook);
  87. menuHelpTipoftheDay = CreateMenuItem( menuHelp, ITEM_PLAIN, "Tip of the Day", null, 'T', "Tip of the Day", AForceMenu.Identification.HelpTipOfTheDay);
  88. menuHelpBugReport = CreateMenuItem( menuHelp, ITEM_PLAIN, "Report a Bug", null, 'B', "Bug reporting", AForceMenu.Identification.HelpBugReporting);
  89. menuHelpDonate = CreateMenuItem( menuHelp, ITEM_PLAIN, "Donate :)", null, 'B', "Please Donate!", AForceMenu.Identification.HelpDonate);
  90. menuHelpAbout = CreateMenuItem( menuHelp, ITEM_PLAIN, "About", null, 'A', "About AForce", AForceMenu.Identification.HelpAboutAForce);
  91. MouseListener mouselistener = new MouseListener()
  92. {
  93. // The menus gain keyboard focus when they are opened, in which case
  94. // we should pause the game! We will resume it when the menus are closed.
  95. public void mouseClicked(MouseEvent e){}
  96. public void mouseEntered(MouseEvent e){}
  97. public void mouseExited(MouseEvent e){}
  98. public void mousePressed(MouseEvent e){if(AForce.clicker.isRunning()) AForce.pause();}
  99. public void mouseReleased(MouseEvent e){}
  100. };
  101. menuGame.addMouseListener(mouselistener);
  102. menuOptions.addMouseListener(mouselistener);
  103. menuHelp.addMouseListener(mouselistener);
  104. }
  105. static class KeepUp implements WindowFocusListener, WindowListener
  106. {
  107. boolean done = false;
  108. public KeepUp(){} // Constructor
  109. public void windowLostFocus(WindowEvent e)
  110. {
  111. if(!done) ((JFrame)e.getSource()).toFront();
  112. }
  113. public void windowGainedFocus(WindowEvent e){}
  114. public void windowActivated(WindowEvent e){}
  115. public void windowClosed(WindowEvent e){done=true;}
  116. public void windowClosing(WindowEvent e){done=true;}
  117. public void windowDeactivated(WindowEvent e){}
  118. public void windowDeiconified(WindowEvent e){}
  119. public void windowIconified(WindowEvent e){}
  120. public void windowOpened(WindowEvent e){}
  121. }
  122. public JMenuItem CreateMenuItem(JMenu menu, int iType, String sText, ImageIcon image, int acceleratorKey, String sToolTip, String idkey)
  123. {
  124. // Create the item
  125. JMenuItem menuItem;
  126. switch(iType)
  127. {
  128. case ITEM_RADIO:
  129. menuItem = new JRadioButtonMenuItem();
  130. break;
  131. case ITEM_CHECK:
  132. menuItem = new JCheckBoxMenuItem();
  133. break;
  134. default:
  135. menuItem = new JMenuItem();
  136. break;
  137. }
  138. // Add the item test
  139. menuItem.setText(sText);
  140. // Add the optional icon
  141. if(image != null) menuItem.setIcon(image);
  142. // Add the accelerator key
  143. if(acceleratorKey > 0) menuItem.setMnemonic( acceleratorKey );
  144. // Add the optional tool tip text
  145. if(sToolTip != null) menuItem.setToolTipText(sToolTip);
  146. // adds the identification key (so we can see what was clicked
  147. menuItem.setActionCommand(idkey);
  148. // Add an action handler to this menu item
  149. menuItem.addActionListener(this);
  150. menu.add(menuItem);
  151. return menuItem;
  152. }
  153. public void setowner(AForce owner)
  154. {
  155. aforce = owner;
  156. }
  157. public void actionPerformed(ActionEvent event)
  158. {
  159. if(event.getActionCommand() == Identification.NewSinglePlayerGame)
  160. {
  161. aforce.newGame();
  162. return;
  163. }
  164. if(event.getActionCommand() == Identification.NewMultiPlayerGame)
  165. {
  166. new Login();
  167. return;
  168. }
  169. if(event.getActionCommand() == Identification.NewCustomGame)
  170. {
  171. new Login();
  172. return;
  173. }
  174. if(event.getActionCommand() == Identification.EXIT)
  175. {
  176. aforce.destroy();
  177. return;
  178. }
  179. if(event.getActionCommand() == Identification.SinglePlayerOptions)
  180. {
  181. new Login();
  182. return;
  183. }
  184. if(event.getActionCommand() == Identification.MultiPlayerOptions)
  185. {
  186. new Login();
  187. return;
  188. }
  189. if(event.getActionCommand() == Identification.HelpHandbook)
  190. {
  191. new WebBrowser("http://www.aforce2.com/help.php");
  192. return;
  193. }
  194. if(event.getActionCommand() == Identification.HelpTipOfTheDay)
  195. {
  196. new TipOfTheDay();
  197. return;
  198. }
  199. if(event.getActionCommand() == Identification.HelpBugReporting)
  200. {
  201. new WebBrowser("http://www.aforce2.com/bugreport.php");
  202. return;
  203. }
  204. if(event.getActionCommand() == Identification.HelpDonate)
  205. {
  206. new WebBrowser("http://www.aforce2.com/donate.php");
  207. return;
  208. }
  209. if(event.getActionCommand() == Identification.HelpAboutAForce)
  210. {
  211. new About();
  212. return;
  213. }
  214. if(event.getActionCommand() == Identification.PauseResume)
  215. {
  216. AForce.pause();
  217. return;
  218. }
  219. if(event.getActionCommand() == Identification.HighScores)
  220. {
  221. aforce.getScoreBoard().buildGUI(aforce);
  222. return;
  223. }
  224. if(event.getActionCommand() == Identification.Save)
  225. {
  226. new Login();
  227. return;
  228. }
  229. if(event.getActionCommand() == Identification.SaveAs)
  230. {
  231. new Login();
  232. return;
  233. }
  234. if(event.getActionCommand() == Identification.ScreenShot)
  235. {
  236. AForce.getFrame().saveSnapShot();
  237. return;
  238. }
  239. Printer.err.println("ERROR 101: Event Not Identified... #AForceMenu.actionPerformed()");
  240. }
  241. public static void main(String args[])
  242. {
  243. Printer.noexecute();
  244. }
  245. public static void promptplayagain(AForce owner)
  246. {
  247. AForce.getClicker().stop();
  248. JOptionPane.showMessageDialog(null, "Game Over!\n Sorry, but you didn't make the high score list.\n Better luck next time!", "Game Over!", JOptionPane.ERROR_MESSAGE);
  249. owner.newGame();
  250. }
  251. public static void madeHighScoreList(JFrame owner, boolean madelist)
  252. {
  253. AForce.getClicker().stop();
  254. if(madelist) JOptionPane.showMessageDialog(owner, "Congratulations,\n You made the high score list!", "Congratulations!", JOptionPane.ERROR_MESSAGE);
  255. else JOptionPane.showMessageDialog(owner, "Game Over!\n Sorry, but you didn't make the high score list.\n Better luck next time!", "Game Over!", JOptionPane.ERROR_MESSAGE);
  256. aforce.newGame();
  257. }
  258. static class Identification
  259. {
  260. public static final String NewSinglePlayerGame = "NewSinglePlayerGame";
  261. public static final String NewMultiPlayerGame = "NewMultiPlayerGame";
  262. public static final String NewCustomGame = "NewCustomGame";
  263. public static final String EXIT = "EXIT";
  264. public static final String SinglePlayerOptions = "SinglePlayerOptions";
  265. public static final String MultiPlayerOptions = "MultiPlayerOptions";
  266. public static final String HelpHandbook = "HelpHandbook";
  267. public static final String HelpTipOfTheDay = "HelpTipOfTheDay";
  268. public static final String HelpBugReporting = "HelpBugReporting";
  269. public static final String HelpDonate = "HelpDonate";
  270. public static final String HelpAboutAForce = "HelpAboutAForce";
  271. public static final String OK = "OK";
  272. public static final String PauseResume = "PauseResume";
  273. public static final String HighScores = "HighScores";
  274. public static final String Save = "Save";
  275. public static final String SaveAs = "SaveAs";
  276. public static final String ScreenShot = "ScreenShot";
  277. }
  278. public static void wrapLabelText(JLabel label, String text)
  279. {
  280. FontMetrics fm = label.getFontMetrics(label.getFont());
  281. int containerWidth = label.getWidth();
  282. BreakIterator boundary = BreakIterator.getWordInstance();
  283. boundary.setText(text);
  284. StringBuffer trial = new StringBuffer();
  285. StringBuffer real = new StringBuffer("<html>");
  286. int start = boundary.first();
  287. for (int end = boundary.next(); end != BreakIterator.DONE;
  288. start = end, end = boundary.next()) {
  289. String word = text.substring(start,end);
  290. trial.append(word);
  291. int trialWidth = SwingUtilities.computeStringWidth(fm,
  292. trial.toString());
  293. if (trialWidth > containerWidth) {
  294. trial = new StringBuffer(word);
  295. real.append("<br> ");
  296. }
  297. real.append(word);
  298. }
  299. real.append("</html>");
  300. label.setText(real.toString());
  301. }
  302. // Special Thanks to Dem for massive help with this WebBrowser class
  303. // http://www.centerkey.com/java/browser/
  304. class WebBrowser
  305. {
  306. WebBrowser(String url)
  307. {
  308. String osName = System.getProperty("os.name");
  309. url += "?os="+osName;
  310. try
  311. {
  312. if (osName.startsWith("Mac OS"))
  313. {
  314. Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
  315. Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
  316. openURL.invoke(null, new Object[] {url});
  317. }
  318. else if (osName.startsWith("Windows"))
  319. Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
  320. else {
  321. //assume Unix or Linux
  322. String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
  323. String browser = null;
  324. for (int count = 0; count < browsers.length && browser == null;count++)
  325. if (Runtime.getRuntime().exec( new String[] {"which", browsers[count]}).waitFor() == 0)
  326. browser = browsers[count];
  327. if (browser == null) Printer.err.println("ERROR 521: Web Browser Not Identified #AForceMenu.WebBrowser.WebBrowser()");
  328. else Runtime.getRuntime().exec(new String[] {browser, url});
  329. }
  330. }
  331. catch (Exception e)
  332. {
  333. Printer.err.println("ERROR 522: Could not launch Web Browser! #AForceMenu.WebBrowser.WebBrowser");
  334. }
  335. }
  336. }
  337. class Login implements DocumentListener, ActionListener
  338. {
  339. private JFrame frame;
  340. private JTextField field1;
  341. private JPasswordField field2;
  342. private JButton button1;
  343. private JLabel label1;
  344. private JLabel label2;
  345. public Login()
  346. {
  347. // NOTE: In order to create the desired output, this example
  348. // uses a NULL layout manager and hard-codes the sizes and
  349. // positions of components. This is NOT something you want
  350. // to do in production code.
  351. frame = new JFrame();
  352. frame.setTitle("Please Login!");
  353. frame.setSize( 300, 190 );
  354. frame.setLocation(new Point(AForce.getFrame().getX()+frame.getX()+(int)frame.getSize().getWidth()/2, AForce.getFrame().getY()+frame.getY()+(int)frame.getSize().getHeight()));
  355. frame.getContentPane().setBackground(Color.gray);
  356. frame.setResizable(false);
  357. frame.addWindowListener(new AForceMenu.KeepUp());
  358. frame.addWindowFocusListener((WindowFocusListener)frame.getWindowListeners()[0]);
  359. JPanel topPanel = new JPanel();
  360. topPanel.setLayout(null);
  361. frame.getContentPane().add(topPanel);
  362. // Create a field and label
  363. field1 = new JTextField();
  364. field1.setBounds( 20, 40, 260, 25 );
  365. field1.setFocusAccelerator( 'v' );
  366. topPanel.add(field1);
  367. label1 = new JLabel("Username:");
  368. label1.setBounds(20, 15, 260, 20);
  369. label1.setLabelFor(field1);
  370. label1.setDisplayedMnemonic('V');
  371. topPanel.add(label1);
  372. // Create a second label and text field
  373. field2 = new JPasswordField();
  374. field2.setBounds(20, 90, 260, 25);
  375. field2.setFocusAccelerator('a');
  376. topPanel.add(field2);
  377. label2 = new JLabel("Password:");
  378. label2.setDisplayedMnemonic('a');
  379. label2.setBounds(20, 65, 260, 20);
  380. label2.setLabelFor(field2);
  381. topPanel.add(label2);
  382. // Create a button and add it to the panel
  383. button1 = new JButton("OK");
  384. button1.setBounds(100, 130, 100, 25);
  385. button1.setEnabled(false);
  386. button1.setActionCommand(Identification.OK);
  387. button1.addActionListener(this);
  388. topPanel.add(button1);
  389. // Add a document listener
  390. Document document;
  391. document = field1.getDocument();
  392. document.addDocumentListener(this);
  393. document = field2.getDocument();
  394. document.addDocumentListener(this);
  395. frame.setVisible(true);
  396. }
  397. // Handle keyboard accelerators
  398. public void actionPerformed( ActionEvent event )
  399. {
  400. if(event.getActionCommand() == Identification.OK)
  401. {
  402. JOptionPane.showMessageDialog(frame, "ERROR: Access Denied!\n Invalid username or password", "ERROR: Access Denied!", JOptionPane.ERROR_MESSAGE);
  403. frame.dispose();
  404. }
  405. }
  406. // Handle insertions into the text field
  407. public void insertUpdate( DocumentEvent event )
  408. {
  409. String username = "";
  410. String password = "";
  411. if(field1 != null && field1.getText() != null)
  412. username = field1.getText();
  413. if(field2 != null && field2.getPassword() != null)
  414. password = new String(field2.getPassword());
  415. if(username.length() >= 3 && password.length() >= 3) button1.setEnabled(true);
  416. else button1.setEnabled(false);
  417. }
  418. // Handle deletions from the text field
  419. public void removeUpdate( DocumentEvent event )
  420. {
  421. insertUpdate(event);
  422. }
  423. // Handle changes to the text field
  424. public void changedUpdate( DocumentEvent event )
  425. {
  426. // Nothing to do here
  427. }
  428. }
  429. class TipOfTheDay implements DocumentListener, ActionListener
  430. {
  431. private JFrame frame;
  432. private JTextField field1;
  433. private JButton button1;
  434. private JLabel label1;
  435. private String[] tips = new String[9];
  436. public TipOfTheDay()
  437. {
  438. TipOfTheDayHelper(((int)(Math.random()*8454761)) % tips.length);
  439. }
  440. public TipOfTheDay(int tipnumber)
  441. {
  442. TipOfTheDayHelper(tipnumber);
  443. }
  444. private void TipOfTheDayHelper(int tipnumber)
  445. {
  446. // Tips!
  447. tips[0] = "You can: press 's' to stop your ship in mid-flight :)";
  448. tips[1] = "If you press 'a', your ship will fly on autopilot";
  449. tips[2] = "If you type 'java AForce Tux', you can play another map";
  450. tips[3] = "Free updates can be found at www.aforce2.com";
  451. tips[4] = "You can press 'p' to pause the game!";
  452. tips[5] = "You can write tips too, email them to tipoftheday@aforce2.com";
  453. tips[6] = "You can fire a laser by waiting 25 seconds and then pressing 'L'";
  454. tips[7] = "You can jump ahead extra fast by pressing 'w' (warp drive)";
  455. tips[8] = "You can place a mine by pressing 'm'";
  456. // NOTE: In order to create the desired output, this example
  457. // uses a NULL layout manager and hard-codes the sizes and
  458. // positions of components. This is NOT something you want
  459. // to do in production code.
  460. frame = new JFrame();
  461. frame.setTitle("Tip Number: "+tipnumber+" ");
  462. frame.setSize( 300, 190 );
  463. frame.setLocation(new Point(AForce.getFrame().getX()+frame.getX()+(int)frame.getSize().getWidth()/2, AForce.getFrame().getY()+frame.getY()+(int)frame.getSize().getHeight()));
  464. frame.getContentPane().setBackground(Color.gray);
  465. frame.setResizable(false);
  466. JPanel topPanel = new JPanel();
  467. topPanel.setLayout(null);
  468. frame.getContentPane().add(topPanel);
  469. label1 = new JLabel();
  470. label1.setBounds(20, 15, 260, 100);
  471. wrapLabelText(label1, "Did you know...<BR><BR> "+tips[tipnumber]);
  472. label1.setLabelFor(field1);
  473. label1.setDisplayedMnemonic('V');
  474. topPanel.add(label1);
  475. // Create a button and add it to the panel
  476. button1 = new JButton("OK");
  477. button1.setBounds(100, 130, 100, 25);
  478. button1.setActionCommand(Identification.OK);
  479. button1.addActionListener(this);
  480. topPanel.add(button1);
  481. frame.setVisible(true);
  482. }
  483. // Handle keyboard accelerators
  484. public void actionPerformed( ActionEvent event )
  485. {
  486. if(event.getActionCommand() == Identification.OK)
  487. {
  488. frame.dispose();
  489. }
  490. }
  491. // Handle insertions into the text field
  492. public void insertUpdate( DocumentEvent event )
  493. {
  494. // Nothing to do here
  495. }
  496. // Handle deletions from the text field
  497. public void removeUpdate( DocumentEvent event )
  498. {
  499. // Nothing to do here
  500. }
  501. // Handle changes to the text field
  502. public void changedUpdate( DocumentEvent event )
  503. {
  504. // Nothing to do here
  505. }
  506. }
  507. class About implements DocumentListener, ActionListener
  508. {
  509. private JFrame frame;
  510. private JTextField field1;
  511. private JButton button1;
  512. private JLabel label1;
  513. public About()
  514. {
  515. frame = new JFrame();
  516. frame.setTitle("About AForce! ");
  517. frame.setSize( 300, 220 );
  518. frame.setLocation(new Point(AForce.getFrame().getX()+frame.getX()+(int)frame.getSize().getWidth()/2, AForce.getFrame().getY()+frame.getY()+(int)frame.getSize().getHeight()));
  519. frame.getContentPane().setBackground(Color.gray);
  520. frame.setResizable(false);
  521. JPanel topPanel = new JPanel();
  522. topPanel.setLayout(null);
  523. frame.getContentPane().add(topPanel);
  524. label1 = new JLabel();
  525. label1.setBounds(10, 10, 260, 130);
  526. wrapLabelText(label1, "Alien Airforce (Original Version by Robert Epps), was rewritten by Jim Sproch in 2006. Many improvements have been made to the game such as the ability to load maps, multiplayer, ability to save games, and an improved score board. This game is copyright 2006 Jim Sproch, all rights reserved.");
  527. label1.setLabelFor(field1);
  528. label1.setDisplayedMnemonic('V');
  529. topPanel.add(label1);
  530. // Create a button and add it to the panel
  531. button1 = new JButton("OK");
  532. button1.setBounds(100, 150, 100, 25);
  533. button1.setActionCommand(Identification.OK);
  534. button1.addActionListener(this);
  535. topPanel.add(button1);
  536. frame.setVisible(true);
  537. }
  538. // Handle keyboard accelerators
  539. public void actionPerformed( ActionEvent event )
  540. {
  541. if(event.getActionCommand() == Identification.OK)
  542. {
  543. frame.dispose();
  544. }
  545. }
  546. // Handle insertions into the text field
  547. public void insertUpdate( DocumentEvent event )
  548. {
  549. // Nothing to do here
  550. }
  551. // Handle deletions from the text field
  552. public void removeUpdate( DocumentEvent event )
  553. {
  554. // Nothing to do here
  555. }
  556. // Handle changes to the text field
  557. public void changedUpdate( DocumentEvent event )
  558. {
  559. // Nothing to do here
  560. }
  561. }
  562. }