public boolean contains(int x, int y){
//(x,y) is in the outer panel's coordinates system
Rectangle2D.Double rectIPS = new Rectangle2D.Double(
topLeftX,topLeftY,imageWidth,imageHeight);
GeneralPath rectPath = new GeneralPath(rectIPS);
rectPath.transform(AffineTransform.getRotateInstance(
angle, (getCenter().x + topLeftX), (getCenter().y + topLeftY))); return rectPath.contains(x, y);
}
是这样的,如果我把红色部分注释掉,直接调用rectIPS.contain(),速度很快,但是加上红色部分以后速度就变慢了,几乎慢了有2秒钟,我想应该就是GeneralPath里面的contains()方法比较慢吧。但是矩形旋转以后还是矩形,慢也不会慢这么多啊