ballworld.java

来自「一些JAVA的小程序」· Java 代码 · 共 55 行

JAVA
55
字号
////	the Ball World game//	Described in Chapter 5 of//	Understanding Object-Oriented Programming with Java//	by Timothy A Budd//	Published by Addison-Wesley////	see ftp://ftp.cs.orst.edu/pub/budd/java/ReadMe.html//	for further information//import java.awt.*;public class BallWorld extends Frame {	public static void main (String [ ] args)	{		BallWorld world = new BallWorld (Color.red);		world.show ();	}	private static final int FrameWidth = 600;	private static final int FrameHeight = 400;	private Ball aBall;	private int counter = 0;	private BallWorld (Color ballColor) {		// constructor for new ball world			// resize our frame		setSize (FrameWidth, FrameHeight);		setTitle ("Ball World");			// initialize object data field		aBall = new Ball (10, 15, 5);		aBall.setColor (ballColor);		aBall.setMotion (3.0, 6.0);	}	public void paint (Graphics g) {			// first, draw the ball		aBall.paint (g);			// then move it slightly		aBall.move();		if ((aBall.x() < 0) || (aBall.x() > FrameWidth))			aBall.setMotion (-aBall.xMotion(), aBall.yMotion());		if ((aBall.y() < 0) || (aBall.y() > FrameHeight))			aBall.setMotion (aBall.xMotion(), -aBall.yMotion());				// finally, redraw the frame		counter = counter + 1;		if (counter < 2000) repaint();		else System.exit(0);	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?