📄 line.java
字号:
import java.awt.Color;
import java.awt.Graphics;
public class Line extends Shape {
private int x, y, x2, y2;
public Line(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.drawLine( x , y, x2, y2);
g.setColor( c );
}
public int compareTo(Object obj) {
System.out.println("comparing lines");
if (obj instanceof Line){
Line line = (Line)obj;
if( ((this.x2 - this.x)* (this.x2 - this.x)+ (this.y2 - this.y) * (this.y2 - this.y))
< ((line.x2 - line.x) * (line.x2 - line.x) + ( line.y2 - line.y ) * ( line.y2 - line.y )))
return -1;
if( ((this.x2 - this.x)* (this.x2 - this.x)+ (this.y2 - this.y) * (this.y2 - this.y))
> ((line.x2 - line.x) * (line.x2 - line.x) + ( line.y2 - line.y ) * ( line.y2 - line.y )))
return 1;
}
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -