jam/ButtonExample

From ggc

Jump to: navigation, search

01 package jam;
02 
03 import fang.*;
04 import java.awt.*;
05 import java.awt.geom.*;
06 
07 /**
08  * All about my game.
09  @author My Name Here
10  */
11 public class ButtonExample extends Game
12 {
13   /**an oval*/
14   private OvalSprite oval;
15   /**button to make red*/
16   private ButtonSprite redButton;
17   /**button to make white*/
18   private ButtonSprite whiteButton;
19 
20   /**sets up the game*/
21   public void setup()
22   {
23     makeSprites();
24     addSprites();
25   }
26 
27   /**makes the sprites*/
28   private void makeSprites()
29   {
30     redButton=new ButtonSprite("Make Red");
31     redButton.setSize(0.5);
32     redButton.setLocation(0.250.8);
33     redButton.enable(this);
34     redButton.addTimedAction(new RedChanger());
35 
36     whiteButton=new ButtonSprite("Make White");
37     whiteButton.setSize(0.5);
38     whiteButton.setLocation(0.750.8);
39     whiteButton.enable(this);
40     whiteButton.addTimedAction(new WhiteChanger());
41 
42     oval=new OvalSprite(0.50.5);
43     oval.setLocation(0.50.3);
44     oval.setColor(Palette.getColor("white"));
45   }
46 
47   class RedChanger extends TimedAction
48   {
49     public void act()
50     {
51       oval.setColor(Palette.getColor("red"));
52     }
53   }
54 
55   class WhiteChanger extends TimedAction
56   {
57     public void act()
58     {
59       oval.setColor(Palette.getColor("white"));
60     }
61   }
62 
63   /**adds the sprites to the screen*/
64   private void addSprites()
65   {
66     addSprite(redButton, whiteButton, oval);
67   }
68 
69 }


Download/View jam/ButtonExample.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter