home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 12,000 to 12,999 / 12000.zip / AOLDLs / Online-Tools / Java-Applets / JAVAAPPS.lzh / JAVAAPPS / CUBEAPP / CUBEAPP.EXE / CubeApp.java < prev    next >
Encoding:
Java Source  |  1996-05-13  |  3.4 KB  |  108 lines

  1.  
  2.  
  3. /*
  4.  
  5.  * Java Rubik's Cube
  6.  
  7.  * -----------------
  8.  
  9.  *
  10.  
  11.  * Copyright 1996, Song Li  
  12.  
  13.  * URL: www.cs.umbc.edu/~sli2
  14.  
  15.  *
  16.  
  17.  * 
  18.  
  19.  * You can use the code for any nonprofittable use. But remember to mention
  20.  
  21.  * the authors' names in your revised program. You are also encouraged to
  22.  
  23.  * improve the program or give your comments and bug reports. If there are
  24.  
  25.  * further questions, please contact me and I'll be glad to help. My E-Mail
  26.  
  27.  * address is: sli2@gl.umbc.edu.
  28.  
  29.  *
  30.  
  31.  */
  32.  
  33.  
  34.  
  35.  
  36.  
  37. import java.applet.Applet;
  38.  
  39. import java.awt.*;
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. public class CubeApp extends Applet {
  48.  
  49.  
  50.  
  51.     private CubePanel   CubeWin ;
  52.  
  53.     
  54.  
  55.     private Button      NewButton ;
  56.  
  57.     private Button      ScrambleButton ;
  58.  
  59.     private Button      SolveButton ;
  60.  
  61.     private Button      AboutButton ;
  62.  
  63.     private Button      UndoButton ;
  64.  
  65.     private Button      RedoButton ;
  66.  
  67.     private Checkbox    SoundCheckbox ;
  68.  
  69.     private Label       StepLabel ;
  70.  
  71.     private TextField   StepText ;
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.     public void init () {
  80.  
  81.         resize(size().width  <= 420 ? 420 : size().width,
  82.  
  83.                size().height <= 200 ? 200 : size().height);
  84.  
  85.       
  86.  
  87.  
  88.  
  89.         setLayout (null);
  90.  
  91.         Panel control = new Panel ();
  92.  
  93.         control.setLayout (null) ;
  94.  
  95.         add (control) ;
  96.  
  97.         control.reshape (0, 0, 200, size().height) ;
  98.  
  99.  
  100.  
  101.         NewButton      = new Button ("New Game") ;
  102.  
  103.         ScrambleButton = new Button ("Scramble") ;
  104.  
  105.         SolveButton    = new Button ("Solve") ;
  106.  
  107.         AboutButton    = new Button ("About") ;
  108.  
  109.         UndoButton     = new Button ("Undo") ;
  110.  
  111.         RedoButton     = new Button ("Redo") ;
  112.  
  113.         SoundCheckbox  = new Checkbox ("Sound") ;
  114.  
  115.         StepLabel      = new Label ("Step") ;
  116.  
  117.         StepText       = new TextField ("0") ;
  118.  
  119.         StepText.setEditable (false) ;
  120.  
  121.         SoundCheckbox.setState (true) ;
  122.  
  123.  
  124.  
  125.         add (NewButton) ;
  126.  
  127.         add (ScrambleButton) ;
  128.  
  129.         add (SolveButton) ;
  130.  
  131.         add (AboutButton) ;
  132.  
  133.         add (UndoButton) ;
  134.  
  135.         add (RedoButton) ;
  136.  
  137.         add (SoundCheckbox) ;
  138.  
  139.         add (StepLabel) ;
  140.  
  141.         add (StepText) ;
  142.  
  143.  
  144.  
  145.         NewButton.reshape      (10,  10, 80, 25) ;  AboutButton.reshape    (110,  10, 80, 25) ;
  146.  
  147.         ScrambleButton.reshape (10,  40, 80, 25) ;  SolveButton.reshape    (110,  40, 80, 25) ;
  148.  
  149.         UndoButton.reshape     (10,  70, 80, 25) ;  RedoButton.reshape     (110,  70, 80, 25) ;
  150.  
  151.         StepLabel.reshape      (10, 160, 40, 25) ;  SoundCheckbox.reshape  (110, 160, 80, 25) ;
  152.  
  153.         StepText.reshape       (40, 158, 40, 29) ;  
  154.  
  155.  
  156.  
  157.         CubeWin = new CubePanel (StepText) ;
  158.  
  159.         CubeWin.setLayout (null) ;
  160.  
  161.         add (CubeWin) ;
  162.  
  163.         CubeWin.reshape (220, 0, size().width-220, size().height) ;
  164.  
  165.         CubeWin.DefineBound () ;
  166.  
  167.  
  168.  
  169.         CubeWin.BadSound  = getAudioClip (getCodeBase (), "illegal.au");
  170.  
  171.         CubeWin.SpinSound = getAudioClip (getCodeBase (), "spin.au");
  172.  
  173.     }
  174.  
  175.  
  176.  
  177.  
  178.  
  179.     public void start () {CubeWin.Start () ;}
  180.  
  181.     public void stop  () {CubeWin.Stop  () ;}
  182.  
  183.  
  184.  
  185.  
  186.  
  187.     public synchronized boolean handleEvent (Event event) {
  188.  
  189.         if (event.id == Event.ACTION_EVENT)
  190.  
  191.             if (event.target == AboutButton) {
  192.  
  193.                 CubeAbout about = new CubeAbout () ;
  194.  
  195.                 about.show () ;
  196.  
  197.             } else
  198.  
  199.                 CubeWin.CommandAction (event) ;
  200.  
  201.         return true ;
  202.  
  203.     }
  204.  
  205.  
  206.  
  207.  
  208.  
  209. }
  210.  
  211.  
  212.  
  213.  
  214.  
  215.