Shape.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 abstract class Shape {
- private Color color; // Shape's color
-
-
- public abstract void drawShape(Graphics page); // draw the Shape
- public abstract boolean containsPoint(Point p); // does the Shape contain
- // Point p?
- public abstract void move(int deltaX, int deltaY); // move the Shape
- public abstract Point getCenter(); // return the Shape's center
- // Create a Shape, setting its color.
- public Shape(Color c) {
- color = c;
- }
- // Set the Shape's color.
- public void setColor(Color newColor) {
- color = newColor;
- }
- // Draw the Shape.
- public void draw(Graphics page) {
- Color savedColor = page.getColor();
- page.setColor(color);
- drawShape(page);
- page.setColor(savedColor);
- }
- // Move the Shape to be a given center.
- public void setCenter(Point newCenter) {
- Point oldCenter = getCenter();
- move(newCenter.x - oldCenter.x, newCenter.y - oldCenter.y);
- }
-
-
- }