home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / MCII.EXE / Controls.java < prev    next >
Encoding:
Java Source  |  1996-10-03  |  2.2 KB  |  100 lines

  1. /* Controls.java - control buttons */
  2.  
  3. /* 
  4.  * Copyright (C) 1996 Mark Boyns <boyns@sdsu.edu>
  5.  *
  6.  * Missile Commando II
  7.  * <URL:http://www.sdsu.edu/~boyns/java/mcii/>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23.  
  24. import java.awt.*;
  25.  
  26. class Controls extends Panel
  27. {
  28.     MissileCommando parent;
  29.  
  30.     Button playButton;
  31.     Button suspendButton;
  32.     Button soundButton;
  33.     
  34.     public Controls (MissileCommando parent)
  35.     {
  36.     this.parent = parent;
  37.     
  38.     setLayout (new FlowLayout ());
  39.  
  40.     playButton = new Button ("Start");
  41.     suspendButton = new Button ("Suspend");
  42.     soundButton = new Button ("Sound Off");
  43.     
  44.     add (playButton);
  45.     add (suspendButton);
  46.     add (soundButton);
  47.     }
  48.  
  49.     public boolean action(Event e, Object arg)
  50.     {
  51.     if (e.target instanceof Button)
  52.     {
  53.         if ("Start".equals (arg))
  54.         {
  55.         if (!parent.playing)
  56.         {
  57.             parent.startGame ();
  58.             playButton.setLabel ("Quit");
  59.         }
  60.         }
  61.         else if ("Quit".equals (arg))
  62.         {
  63.         if (parent.playing)
  64.         {
  65.             parent.quitGame ();
  66.             playButton.setLabel ("Start");
  67.         }
  68.         }
  69.         else if ("Suspend".equals (arg))
  70.         {
  71.         if (parent.playing)
  72.         {
  73.             parent.suspendGame ();
  74.             suspendButton.setLabel ("Resume");
  75.         }
  76.         }
  77.         else if ("Resume".equals (arg))
  78.         {
  79.         if (parent.paused)
  80.         {
  81.             parent.resumeGame ();
  82.             suspendButton.setLabel ("Suspend");
  83.         }
  84.         }
  85.         else if ("Sound Off".equals (arg))
  86.         {
  87.         parent.disableSound ();
  88.         soundButton.setLabel ("Sound On");
  89.         }
  90.         else if ("Sound On".equals (arg))
  91.         {
  92.         parent.enableSound ();
  93.         soundButton.setLabel ("Sound Off");
  94.         }
  95.         return true;
  96.     }
  97.         return false;
  98.     }
  99. }
  100.