【发布时间】:2014-10-24 22:40:39
【问题描述】:
我想创建一个边界框来选择一个形状。我有一个形状向量和一个所有点的向量。目标是在边界框内放置一些形状,然后我可以应用一些变换,例如在画布周围移动一些形状、旋转、调整大小等。
现在我专注于选择和移动某些形状的边界框。其他转换留待以后使用。
这是类,我知道至少我需要这个变量
public class BoundingBox {
int xmax;
int xmin;
int ymax;
int ymin;
public BoundingBox(Vector<Point> points) {
}
我还实现了其他类,例如,我有一个带有此功能的编辑器面板
Vector<Shape> shapes;
// Current shape that is in construction (if any)
Shape currentShape;
// shape that is selected, if any
Shape selectedShape;
实现形状的类
protected Vector<Point> points;
protected boolean isAShapeBeingBuilt; //is any shape being built?
protected boolean selected; //is any shape selected?
protected ShapesEditorPanel parent; // reference to the panel
显然,我不能将所有代码都放在这里,但我希望通过这些信息可以帮助我。主要问题是如何选择和移动框内的一些形状!
【问题讨论】:
-
不确定我是否理解这个问题。
Shape类已经支持getBounds()方法来获取Shape 的边界Rectangle。 -
我的形状课?还是你指的是java的shape类?
-
Java 的
Shape类。我回答的重点是您应该使用 Java 的 Shape 类。它已经提供了您需要的功能。 -
是的,但我不能使用那个类。在这项工作中应该“手工”完成所有这些工作:D 无论如何,谢谢!