swing - Java JComponent doesn't refresh -
i've got problem class component. problem ovals doesn't changing colors. function if observing ovf flag in class counter. when ovf=true ovals should red, , when ovf=false ovals should white. in gui can see red ovals (even if ovf=false). try add repaint() command red ovals started blinking. here code:
import java.awt.*; import javax.swing.*; import java.util.observable; public class komponent extends jcomponent { counter counter3; public komponent() { counter3=new counter(); } public void paint(graphics g) { graphics2d dioda = (graphics2d)g; int x1 = 85; int x2 = 135; int y = 3; int width = (getsize().width/9)-6; int height = (getsize().height-1)-6; if (counter3.ovf = true) { dioda.setcolor(color.red); dioda.filloval(x1, y, width, height); dioda.filloval(x2, y, width, height); } if (counter3.ovf = false) { dioda.setcolor(color.white); dioda.filloval(x1, y, width, height); dioda.filloval(x2, y, width, height); } } public static void main(string[] arg) { new komponent(); } } what wrong code?
if should be:
if (counter3.ovf == true) { // watch out = , == // red } if (counter3.ovf == false) { // white } or simpler:
if (counter3.ovf) { // red } else { // white } or simplest:
dioda.setcolor(counter3.ovf ? color.red : color.white); dioda.filloval(x1, y, width, height); dioda.filloval(x2, y, width, height);
Comments
Post a Comment