⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 square.java

📁 能够画线条、圆和长方形的Java程序
💻 JAVA
字号:
import java.awt.Color;
import java.awt.Graphics;

public class Square extends Shape {
	private int x, y, x2, y2;
		
	public Square(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.drawRect( x , y, x2, y2);		
		g.setColor( c );
	}
	public int compareTo(Object obj) {
		System.out.println("comparing Squares");
		if (obj instanceof Square){
			Square square = (Square)obj;
			if( this.x2 + this.y2 < square.x2 + square.y2)
				return -1;
			if( this.x2 + this.y2 > square.x2 + square.y2)
				return 1;
		}		
		return 0;
	}

	
		
}	// end of Square class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -