📄 circle.java
字号:
import java.awt.*;
import java.awt.geom.*;
// This will draw a circle on the Canvas, used for the pieces.
public class Circle
{
private int diameter;
private int xPosition;
private int yPosition;
private String color;
private boolean isVisible;
// Creates a single circle at the default setup / variables.
public Circle()
{
diameter = 30;
xPosition = 0;
yPosition = 0;
color = "red";
isVisible = true;
}
// Move the circle HORIZONTALLY by the 'distance' pixels.
public void moveHorizontal(int distance)
{
erase();
xPosition += distance;
draw();
}
// Move the circle VERTICALLY by the 'distance' pixels.
public void moveVertical(int distance)
{
erase();
yPosition += distance;
draw();
}
// Change size
public void changeSize(int newDiameter)
{
erase();
diameter = newDiameter;
draw();
}
// Change the colour, only colours used will be BLACK or WHITE.
public void changeColor(String newColor)
{
color = newColor;
draw();
}
// Draw the circle with current specs on the screen.
private void draw()
{
if(isVisible) {
Canvas canvas = Canvas.getCanvas();
canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition,
diameter, diameter));
}
}
// Erase the circle on the screen at call time.
private void erase()
{
if(isVisible) {
Canvas canvas = Canvas.getCanvas();
canvas.erase(this);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -