我的问题如下。我正在使用标准的 SWING 事件调度线程来绘制一个具有低 alpha 值的椭圆,并在中心绘制另一个较小的椭圆来表示其中心。当我运行模拟时,我使用一个单独的线程,并允许用户在模拟运行时添加这些障碍。现在,当单独的线程未运行但单独的模拟线程正在运行时,这可以正常工作,较大的椭圆(应该用低 alpha 绘制)不会用低 alpha 值绘制,因此会创建一个实体大红色椭圆形。为什么会发生这种情况,我该如何解决?
如果我的解释不太清楚,请告诉我。
private void drawObstacleCircle(Obstacle o, Graphics2D g)
{
final double OBSTACLE_CENTER_RADIUS = 2.0;
final double OBSTACLE_RADIUS = o.getRadius(true);
float scaleToUse = Math.max(0.8f, scale);
Vector pos = o.getPosition();
int xPos = (int) (pos.getX() * getBufferedHeightMap().getWidth());
int yPos = (int) (pos.getY() * getBufferedHeightMap().getHeight());
Point positionPoint = convertToPanelPoint(new Point(xPos, yPos));
// Draw the circle where the Obstacle's center is
Graphics2D g1 = (Graphics2D) g.create();
g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g1.setColor(Color.RED);
g1.fillOval(positionPoint.x - (int) (OBSTACLE_CENTER_RADIUS * scaleToUse), positionPoint.y - (int) (OBSTACLE_CENTER_RADIUS * scaleToUse), (int) (OBSTACLE_CENTER_RADIUS * 2 * scaleToUse), (int) (OBSTACLE_CENTER_RADIUS * 2 * scaleToUse));
Color c = Color.RED;
g1.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 100));
g1.fillOval(positionPoint.x - (int) (OBSTACLE_RADIUS * scaleToUse), positionPoint.y - (int) (OBSTACLE_RADIUS * scaleToUse), (int) (OBSTACLE_RADIUS * 2 * scaleToUse), (int) (OBSTACLE_RADIUS * 2 * scaleToUse));
g1.dispose();
g2.dispose();
}