checkbox help!
807597Mar 26 2005 — edited Mar 26 2005//A bouncing ball animation
import java.awt.*; //import the awt package
import javax.swing.JFrame; //import the JFrame class from the swing package
public class BallWorld extends JFrame{
public static void main (String [] args){
BallWorld world = new BallWorld(Color.red);
world.show();
for(int i = 0; i < 1000; i++) world.run();
System.exit(0);
}
public static final int FrameWidth = 600;
public static final int FrameHeight = 400;
private Ball aBall = new Ball(new Point(50,50), 20);
private BallWorld(Color ballColor) { //constructor for new window
//resize frame, initialize title
setSize(FrameWidth, FrameHeight);
setTitle("Ball World");
//set colour and motion of ball
aBall.setColor(ballColor);
aBall.setMotion(3.0, 6.0);
}
public void paint (Graphics g) {
//first draw the ball
super.paint(g);
aBall.paint(g);
}
public void run(){
//move ball slightly
aBall.move();
//next, check whether it intersects with a boundary and,
//if so, change direction of motion
Point pos = aBall.location();
if ((pos.x < aBall.radius()) ||
(pos.x > FrameWidth - aBall.radius()))
aBall.reflectHorz();
if ((pos.y < aBall.radius()) ||
(pos.y > FrameHeight - aBall.radius()))
aBall.reflectVert();
repaint();
try{
Thread.sleep(50);
} catch(InterruptedException e) {System.exit(0);}
}
}
can any help me add a checkbox which can be labeled into this code???
also statements that when the checkbox is checked, it will enlarge the size of the ball by 10 and reset its position to the centre of the window. When it is unchecked, the size of the ball reverts to its original size!
thanks so much guys!