我的程序创建Circles
和Squares
并将它们放置在DrawZone
的中心。我要做的是将它们移到我用鼠标单击的位置。为此,我使用MouseListener
。
但是,此步骤已实现,当我移动表格时,我想将颜色更改为RED,但它不起作用。我不明白为什么,但是我的表单移动到了鼠标的位置,但是它改变了下一个表单的颜色(我的ArrayList
不变)。
这是我的代码:
if(SwingUtilities.isLeftMouseButton(arg0)) {
if(ListeForme2D.isEmpty()) {
System.out.println("No way to move something that doesn't exist !");
} else {
ArrayList<Forme2D> updateList = new ArrayList<Forme2D>(ListeForme2D);
initialColor = ListeForme2D.get(0).getColor();
ListeForme2D.clear();
updateList.get(0).setColor(Color.red);
updateList.get(0).setTranslation(arg0.getX(), arg0.getY());
repaint();
for(int i=0; i<updateList.size(); i++) {
ListeForme2D.add(updateList.get(i));
}
repaint();
}
}
黑色的移动到了点击点,但是没有达到预期的红色,但是第二个变成了红色。如下所示: