I have a problem with my Component in Java. When i set OVF flag to true, Rect should be in Color red (255,0,0), and if i set OVF flag to false, Rect should be in color blue (0,0,255). The problem is that I can see in my GUI only blue rectangle (even if OVF flag is set to true). What should I change in this code?
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import javax.swing.*;
public class Komponent2 extends JComponent implements ActionListener
{
Timer tm = new Timer(10, this);
int x =30;
int y =0, y2 = 8;
Counter counter3;
Color Kolor = new Color(255,255,255);
public void paintComponent(Graphics g)
{
counter3=new Counter();
super.paintComponent(g);
g.setColor(Kolor);
g.fillRect(y,30,x,30);
tm.start();
}
public void actionPerformed(ActionEvent e)
{
if(y<0 || y>300)
y2=-y2;
y=y + y2;
if (counter3.OVF==true)
Kolor = new Color (255,0,0);
if (counter3.OVF==false)
Kolor = new Color (0,0,255);
repaint ();
}
}
Thanks for helping me.