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

📄 ex050203.java

📁 我在学习JAVA的讲义
💻 JAVA
字号:
import java.io.*;
import java.awt.*;

class R_Rectangle extends Rectangle{
	public R_Rectangle(){
		p = new Point(0,0);
	}
	
	public R_Rectangle(Rectangle r, Point p){
		super(r);
		this.p= new Point(p);
	}
	
	public R_Rectangle(int x, int y, int width, int height){
		super(width,height);
		p=new Point(x,y);
	}
	
	public boolean contains(Point p){
		if (this.p.getX()<=p.getX() && 
			this.p.getX()+this.getWidth()>=p.getX() &&
			this.p.getY()<=p.getY() && 
			this.p.getY()+this.getHeight()>=p.getY())
			return true;
		return false;
	}
	public void moveTo(int x, int y){
		this.p.setLocation(x,y);
	}
	
	public Point getWhere(){
		return new Point((int)p.getX(),(int)p.getY());
	}

	private Point p;
	
}

public class Ex050203{
	public static void main(String[] args){
		Rectangle r = new Rectangle(30,70);
		Point p = new Point(25,10);
		R_Rectangle rr1 = new R_Rectangle(r,p);

		System.out.println("rr1.getWhere="+ rr1.getWhere());
		rr1.moveTo(100,100);
		System.out.println("rr1.getWhere="+ rr1.getWhere());
		
		System.out.println("rr1.contains(Point(25,10))="+ rr1.contains(p));
		p=new Point(110,125);
		System.out.println("rr1.contains(Point(110,125))="+ rr1.contains(p));
		
	}

}

⌨️ 快捷键说明

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