Rectangle.java
上传用户:sdzznc
上传日期:2022-07-23
资源大小:51k
文件大小:1k
- // Copyright by Scot Drysdale
- package cn.edu.nju.software.grapheditor.shape;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Point;
- public class Rectangle extends Shape {
- public Point startPoint,endPoint;
- int width,height;
- public Rectangle(Color c) {
- super(c);
- }
- @Override
- public boolean containsPoint(Point p) {
- if((p.x-startPoint.x)*(p.x-endPoint.x)<=0&&(p.y-startPoint.y)*(p.y-endPoint.y)<=0){
- return true;
- }
- else{
- return false;
- }
- }
- @Override
- public void drawShape(Graphics page) {
- width=endPoint.x-startPoint.x;
- height=endPoint.y-startPoint.y;
- page.fillRect(startPoint.x, startPoint.y, width, height);
-
- }
- @Override
- public Point getCenter() {
-
- return new Point( (int)(startPoint.x+endPoint.x)/2,(int)(startPoint.y+endPoint.y)/2);
- }
- @Override
- public void move(int deltaX, int deltaY) {
- startPoint.x=startPoint.x+deltaX;
- startPoint.y=startPoint.y+deltaY;
- endPoint.x=endPoint.x+deltaX;
- endPoint.y=endPoint.y+deltaY;
- // TODO Auto-generated method stub
-
- }
- // YOU FILL IN INSTANCE VARIABLES AND METHODS.
- }