⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ball.java

📁 一些JAVA的小程序
💻 JAVA
字号:
////	general purpose reusable bounding ball abstraction////	From Chapter 5 of//	Understanging Object-Oriented Programming with Java//	Written by Tim Budd//	Published by Addison-Wesley Longman////	See ftp://ftp.cs.orst.edu/pub/budd/java/ReadMe.html //	for further information//import java.awt.*;public class Ball {	protected Rectangle location;	protected double dx;	protected double dy;	protected Color color;		public Ball (int x, int y, int r)	{		location = new Rectangle(x-r, y-r, 2*r, 2*r);		dx = 0;		dy = 0;		color = Color.blue;	}			// functions that set attributes	public void setColor (Color newColor)				{ color = newColor;	}	public void setMotion (double ndx, double ndy)				{ dx = ndx; dy = ndy; }			// functions that access attributes of ball	public int radius ()				{ return location.width / 2; }		public int x ()				{ return location.x + radius(); }		public int y ()				{ return location.y + radius(); }		public double xMotion ()				{ return dx; }	public double yMotion ()				{ return dy; }	public Rectangle region () { return location; }		// functions that change attributes of ball	public void moveTo (int x, int y)				{ location.setLocation(x, y); }	public void move ()				{ location.translate ((int) dx, (int) dy); }		public void paint (Graphics g)	{		g.setColor (color);		g.fillOval (location.x, location.y, location.width, location.height);	}}

⌨️ 快捷键说明

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