やあみんな。クリックすると色が変わるJPanelを持っています(これは別のクラスで正しく処理されます)。
残念ながら、repaint()メソッドを呼び出すと、ペイントされません(または、var currentBGColorの古いColor値を使用してpaintComponentメソッドを呼び出します->以下のコードを参照してください)
public class MyClass extends JPanel {
curentBGColor = Color.red;
final int SIZE = 70;
public MyClass (){
setPreferredSize (new Dimension (SIZE,SIZE));
}
public void paintComponent (Graphics g)
{
g.setColor (currentBGColor); //I want this to paint white when newColor() is called
g.fillRect (0,0,getWidth(),getHeight());
g.setColor (Color.black);
g.drawLine (0,0,SIZE-1,0);
g.drawLine (0,0,0,SIZE-1);
g.drawLine (0,SIZE-1,SIZE-1,SIZE-1);
g.drawLine (SIZE-1,0,SIZE-1,SIZE-1);
}
void newColor (){
currentBGColor = Color.white;
repaint ();
revalidate();
}
}
なぜそれが新しい色で塗られていないのか誰かが知っていますか?