home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-03 | 2.2 KB | 100 lines |
- /* Controls.java - control buttons */
-
- /*
- * Copyright (C) 1996 Mark Boyns <boyns@sdsu.edu>
- *
- * Missile Commando II
- * <URL:http://www.sdsu.edu/~boyns/java/mcii/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- import java.awt.*;
-
- class Controls extends Panel
- {
- MissileCommando parent;
-
- Button playButton;
- Button suspendButton;
- Button soundButton;
-
- public Controls (MissileCommando parent)
- {
- this.parent = parent;
-
- setLayout (new FlowLayout ());
-
- playButton = new Button ("Start");
- suspendButton = new Button ("Suspend");
- soundButton = new Button ("Sound Off");
-
- add (playButton);
- add (suspendButton);
- add (soundButton);
- }
-
- public boolean action(Event e, Object arg)
- {
- if (e.target instanceof Button)
- {
- if ("Start".equals (arg))
- {
- if (!parent.playing)
- {
- parent.startGame ();
- playButton.setLabel ("Quit");
- }
- }
- else if ("Quit".equals (arg))
- {
- if (parent.playing)
- {
- parent.quitGame ();
- playButton.setLabel ("Start");
- }
- }
- else if ("Suspend".equals (arg))
- {
- if (parent.playing)
- {
- parent.suspendGame ();
- suspendButton.setLabel ("Resume");
- }
- }
- else if ("Resume".equals (arg))
- {
- if (parent.paused)
- {
- parent.resumeGame ();
- suspendButton.setLabel ("Suspend");
- }
- }
- else if ("Sound Off".equals (arg))
- {
- parent.disableSound ();
- soundButton.setLabel ("Sound On");
- }
- else if ("Sound On".equals (arg))
- {
- parent.enableSound ();
- soundButton.setLabel ("Sound Off");
- }
- return true;
- }
- return false;
- }
- }
-