The Artima Developer Community
Sponsored Link

Java Answers Forum
Repaint question

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Steve Jurkovic

Posts: 1
Nickname: cubfan
Registered: Apr, 2007

Repaint question Posted: Apr 28, 2007 3:41 PM
Reply to this message Reply
Advertisement
Hi, I've been trying to track down a problem I am having.

I'm changing Red/Yellow/Green by calling setRed etc and calling repaint(). It seems to somewhat be working, in that I can track it going through paintComponent. However, it not repainting the screen.

I understand things may 'wait' for a while, (and I don't want this to sound too dumb) but are we saying it could take a minutes to repaint, which seems like forever. When I stretch the screen - boom - repaints immediately.

If I use a value in repaint(long x) what would an appropriate value be? Have also tried to put validate() in place of (and in conjunction with) repaint.



public class NewPanel extends JPanel {


public static boolean Red = false;
public static boolean Yellow = false;
public static boolean Green = false;


public void paintComponent(Graphics g) {
super.paintComponent(g);

System.out.println("in paintcomponent");
System.out.println("Red = " + Red + " Yellow = " + Yellow +
" Green = " + Green);


if(Red) {
System.out.println("In Red Logic");
g.setColor(Color.RED);
g.fillOval(220,50,50,50);
g.setColor(Color.BLACK);
g.drawOval(220,110,50,50);
g.drawOval(220,170,50,50);

}
else if(Yellow) {
System.out.println("In Yellow Logic");
g.setColor(Color.YELLOW);
g.fillOval(220,110,50,50);
g.setColor(Color.BLACK);
g.drawOval(220,50,50,50);
g.drawOval(220,170,50,50);
}
else if(Green){
System.out.println("In Green Logic");
g.setColor(Color.GREEN);
g.fillOval(220,170,50,50);
g.setColor(Color.BLACK);
g.drawOval(220,50,50,50);
g.drawOval(220,110,50,50);
}
else {
System.out.println("In Default Logic");
g.setColor(Color.BLACK);
g.drawOval(220,50,50,50);
g.drawOval(220,110,50,50);
g.drawOval(220,170,50,50);
}

} // end paintComponent


public void setRed(){
System.out.println("Setting Red to True");
Red = true;
Yellow = false;
Green = false;
repaint();
}
public void setYellow(){
System.out.println("Setting Yellow to True");
Red = false;
Yellow = true;
Green = false;
repaint();

}
public void setGreen(){
System.out.println("Setting Green to True");
Red = false;
Yellow = false;
Green = true;
repaint();

}
}

Topic: Repaint question Previous Topic   Next Topic Topic: Need help!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use