📄 bball.java
字号:
import objectdraw.*;import java.awt.*;// A class that draws a nice looking basketball that can be// moved about the displaypublic class BBall { // the color to draw the ball private static final Color BALL_ORANGE = new Color(250,85,10); // size of cut arc in degrees private static final int CUTSIZE = 100; // offset to start of arcs in degrees private static final int RIGHTCUTSTART = 90 + (180-CUTSIZE)/2; private static final int LEFTCUTSTART = 270 + (180-CUTSIZE)/2; // the orange part of the ball private FilledOval body; // the black frame around the ball private FramedOval border; // the two curves on the sides of the ball private FramedArc leftCut, rightCut; // the vertical and horizontal lines through the ball private Line vert, horiz; // initial coordinates of basketball double initX, initY; // Create a new basketball public BBall(double left, double top, double size, DrawingCanvas aCanvas ) { // remember the ball's starting position initX = left; initY = top; // draw the circles that make it look like a ball body = new FilledOval(left, top, size, size, aCanvas); body.setColor(BALL_ORANGE); border = new FramedOval( left, top, size, size, aCanvas); // draw the lines through the circle that make it look // like a basketball vert = new Line( left + size/2,top, left + size/2, top+size,aCanvas); horiz = new Line( left,top+size/2, left + size, top+size/2,aCanvas); rightCut = new FramedArc( left+size*2/3, top, size, size, RIGHTCUTSTART, CUTSIZE, aCanvas); leftCut = new FramedArc( left-size*2/3, top, size, size, LEFTCUTSTART, CUTSIZE, aCanvas); } // move the ball by specified offsets public void move( double dx, double dy) { // move each part of the ball by the offsets provided body.move(dx,dy); border.move(dx,dy); vert.move(dx,dy); horiz.move(dx,dy); leftCut.move(dx,dy); rightCut.move(dx,dy); } // move the ball to a specified position public void moveTo( double x, double y ) { // move the ball by the offsets needed to reach desired location this.move ( x - body.getX(), y - body.getY() ); } // check to see if the ball contains a specified location public boolean contains( Location point) { return body.contains(point); } // return the ball to its starting position public void reset ( ) { this.moveTo( initX, initY ); } // hide all the parts of a basketball public void hide( ) { body.hide(); border.hide(); vert.hide(); horiz.hide(); leftCut.hide(); rightCut.hide(); } // show all the parts of a basketball public void show( ) { body.show(); border.show(); vert.show(); horiz.show(); leftCut.show(); rightCut.show(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -