?? element.java
字號:
import java.awt.*;
import java.awt.geom.*;
public abstract class Element
{
public Element(Color color)
{
this.color = color;
}
public Color getColor()
{
return color;
}
// Nested class defining a line
public static class Line extends Element
{
public Line(Point start, Point end, Color color)
{
super(color);
line = new Line2D.Double(start, end);
}
public Shape getShape()
{
return line;
}
public java.awt.Rectangle getBounds()
{
return line.getBounds();
}
public void modify(Point start, Point last)
{
line.x2 = last.x;
line.y2 = last.y;
}
private Line2D.Double line;
}
// Nested class defining a rectangle
public static class Rectangle extends Element
{
public Rectangle(Point start, Point end, Color color)
{
super(color);
this.start = start; // Save the start point
rectangle = new Rectangle2D.Double(
Math.min(start.x, end.x), Math.min(start.y, end.y), // Top-left corner
Math.abs(start.x - end.x), Math.abs(start.y - end.y)); // Width & height
}
public Shape getShape()
{
return rectangle;
}
public java.awt.Rectangle getBounds()
{
return rectangle.getBounds();
}
public void modify(Point start, Point last)
{
rectangle.x = Math.min(start.x, last.x);
rectangle.y = Math.min(start.y, last.y);
rectangle.width = Math.abs(start.x - last.x);
rectangle.height = Math.abs(start.y - last.y);
}
private Rectangle2D.Double rectangle;
private Point start;
}
public abstract Shape getShape();
public abstract java.awt.Rectangle getBounds();
protected Color color; // Color of a shape
public abstract void modify(Point start, Point last);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -