framedball.java
来自「书籍"Java_面向事件编程"的附带光盘代码」· Java 代码 · 共 61 行
JAVA
61 行
import objectdraw.*;import java.awt.Color;// A simple, round oval will a black border and a filled interior.public class FramedBall { // the interior of the ball private FilledOval body; // the black frame around the ball private FramedOval border; // Create the Framed and Filled ovals to make a ball with a border public FramedBall( double left, double top, double size, DrawingCanvas aCanvas) { body = new FilledOval(left, top, size, size, aCanvas); border = new FramedOval(left, top, size, size, aCanvas); } // move the ball by specified offsets public void move(double dx, double dy) { body.move(dx, dy); border.move(dx, dy); } // set the color of the interior of the ball public void setColor(Color hue) { body.setColor(hue); } // get the x coordinate of the corner of the ball public double getX() { return body.getX(); } // get the y coordinate of the corner of the ball public double getY() { return body.getY(); } // check to see if the ball contains a specified location public boolean contains(Location point) { return body.contains(point); } // move the ball to a specified position public void moveTo(double x, double y) { // move the ball by offsets needed to reach desired location this.move(x - body.getX(), y - body.getY()); } // move the ball to a specified position public void moveTo(Location point) { this.moveTo(point.getX(), point.getY()); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?