如果java.awt.Rectangle允许,以下是您如何在实现中使用它的概述:
private static class Rectangle {
private int x1, y1, x2, y2, r, g, b;
private java.awt.Rectangle r1 = new java.awt.Rectangle();
private java.awt.Rectangle r2 = new java.awt.Rectangle();
private java.awt.Rectangle r3;
public Rectangle(int x1, int y1, int x2, int y2, int r, int g, int b) {
...
}
private void draw(Graphics page) {
...
}
private boolean overlapsWith(Rectangle r) {
r1.setBounds(...);
r2.setBounds(...);
return r1.intersects(r2);
}
private Rectangle getOverlap(Rectangle r) {
r1.setBounds(...);
r2.setBounds(...);
r3 = r1.intersection(r2);
return new Rectangle(...);
}