我有一个分为多个扇区的面板。我已经附加了一个MouseListener。每个拖动事件都会生成一个点,将其添加到ArrayList并调用重绘。拖动鼠标时,通过循环播放ArrayList并调用Graphics2D旋转方法,在每个扇区中绘制鼠标模式。如果我慢慢拖动鼠标,我可以看到屏幕上逐渐绘制的点。我该如何解决这个问题?
//performs the drawing on the display panel
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(penColor);
this.sectorLine = new Line2D.Double(getCenterX(), getCenterY(), getCenterX(), 0);
g2d.setClip( new Ellipse2D.Double(getCenterX() - getLineLength(), getCenterY() - getLineLength(), getLineLength()*2, getLineLength()*2));
//draws the sectors on the screen
if(drawSectors)
{
drawSectorLines(g2d);
}
for (Point point : points)
{
g2d.fillOval((int) point.getX() -4 , (int) point.getY() -4,8, 8); // has to return the size of the pen /2 methog get offset
// dva metoda za sektori i rotate
rotate(g2d,getNumberOfSectors() - 1);
}
}
//rotates each drawn point in every sector
public void rotate(Graphics2D g2d, int times)
{
g2d.setColor(penColor);
for(int i=0; i<times; i++)
{ // returns 360/number of sectors
g2d.rotate(Math.toRadians(getRotationDegrees()), getWidth()/2, getHeight()/2);
}
}
// handles drawing
private class DisplayListener extends MouseAdapter
{
private void addPoint(MouseEvent event)
{
Point point = event.getPoint();
points.add(point);
repaint();
}
public void mouseClicked(MouseEvent event)
{
addPoint(event);
}
public void mouseDragged(MouseEvent event)
{
addPoint(event);
}
}