aboutsummaryrefslogtreecommitdiffstats
path: root/docs/dist/examples/spacewar/SWFrame.java
diff options
context:
space:
mode:
authorwisberg <wisberg>2002-12-16 17:58:19 +0000
committerwisberg <wisberg>2002-12-16 17:58:19 +0000
commitd842c4f1139629c1f062b74ba818d233b2c31043 (patch)
tree842d3871620bc0eb60edcd95e55804d67e0f61fa /docs/dist/examples/spacewar/SWFrame.java
parent3ce247199704eae6b2c92c6e38c69584e3250c52 (diff)
downloadaspectj-d842c4f1139629c1f062b74ba818d233b2c31043.tar.gz
aspectj-d842c4f1139629c1f062b74ba818d233b2c31043.zip
initial version
Diffstat (limited to 'docs/dist/examples/spacewar/SWFrame.java')
-rw-r--r--docs/dist/examples/spacewar/SWFrame.java92
1 files changed, 92 insertions, 0 deletions
diff --git a/docs/dist/examples/spacewar/SWFrame.java b/docs/dist/examples/spacewar/SWFrame.java
new file mode 100644
index 000000000..6dfb9f6f6
--- /dev/null
+++ b/docs/dist/examples/spacewar/SWFrame.java
@@ -0,0 +1,92 @@
+/*
+
+Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
+
+Use and copying of this software and preparation of derivative works based
+upon this software are permitted. Any distribution of this software or
+derivative works must comply with all applicable United States export control
+laws.
+
+This software is made available AS IS, and Xerox Corporation makes no warranty
+about the software, its performance or its conformity to any specification.
+
+|<--- this code is formatted to fit into 80 columns --->|
+|<--- this code is formatted to fit into 80 columns --->|
+|<--- this code is formatted to fit into 80 columns --->|
+
+
+SWFrame.java
+Part of the Spacewar system.
+
+*/
+
+package spacewar;
+
+import java.awt.Frame;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+import java.awt.MenuShortcut;
+import java.awt.Dimension;
+import java.awt.Insets;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+class SWFrame extends Frame implements ActionListener {
+ private Game game;
+ private Display display;
+ private Menu menu;
+
+ Game getGame() { return game; }
+ Display getDisplay() { return display; }
+ Menu getMenu() { return menu; }
+
+ SWFrame(Game theGame, Display d) {
+ super("Space War!");
+
+ game = theGame;
+
+ display = d;
+ add(display);
+
+ // create menu
+ menu = new Menu("Game");
+ MenuItem item1 = new MenuItem("Add Robot", new MenuShortcut('a'));
+ MenuItem item2 = new MenuItem("Reset Ships", new MenuShortcut('r'));
+ MenuItem item3 = new MenuItem("Quit", new MenuShortcut('q'));
+ item1.setActionCommand("Add Robot");
+ item2.setActionCommand("Reset Ships");
+ item3.setActionCommand("Quit");
+ menu.add(item1);
+ menu.add(item2);
+ menu.add(item3);
+ menu.addActionListener(this);
+
+ setMenuBar(new MenuBar());
+ getMenuBar().add(menu);
+
+ Dimension screenSize = new Dimension(500, 500);
+ setSize(screenSize);
+ setVisible(true);
+ toFront();
+
+ Insets inset = getInsets();
+ int displayWidth = screenSize.width - inset.left - inset.right;
+ int displayHeight = screenSize.height - inset.top - inset.bottom;
+ display.setSize(displayWidth, displayHeight);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ String s = e.getActionCommand();
+ if (s.equals("Add Robot")) {
+ getGame().addRobot();
+ }
+ else if (s.equals("Reset Ships")) {
+ getGame().resetShips();
+ }
+ else if (s.equals("Quit")) {
+ getGame().quit();
+ }
+ }
+}