circle.java
来自「能够画线条、圆和长方形的Java程序」· Java 代码 · 共 40 行
JAVA
40 行
import java.awt.Color;
import java.awt.Graphics;
public class Circle extends Shape {
private int x, y, x2, y2;
public Circle(int x, int y, int x2, int y2){
this.x = x;
this.y = y;
this.x2 = x2;
this.y2 = y2;
}
public void draw(Graphics g){
Color c = g.getColor();
if( isVisible() == false ){
g.setColor( getBackgroundColor() );
}
g.drawOval( x , y, x2, y2);
g.setColor( c );
}
public int compareTo(Object obj) {
System.out.println("comparing Circles");
if (obj instanceof Circle){
Circle circle = (Circle)obj;
if( this.x2 + this.y2 < circle.x2 + circle.y2)
return -1;
if( this.x2 + this.y2 > circle.x2 + circle.y2)
return 1;
}
return 0;
}
} // end of Circle class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?