ex050203.java
来自「我在学习JAVA的讲义」· Java 代码 · 共 56 行
JAVA
56 行
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 + =
减小字号Ctrl + -
显示快捷键?