Re: repaint doesn't work
To: comp.lang.java.gui
post an SSCCE* and I
might reconsider.
This is the code. Output must be "writed Wait", then "writed Done", and
I must see "Wait", and then "Done" on Frame. But I see only "Done" and
"writed Done" at end.
import java.awt.*;
import java.awt.event.*;
class test
{
public static void main(String[]args)
{new window();}
}
class window extends Frame
{
private int max=10;
private void work(write w)
{
long stop=(new java.util.Date()).getTime()+max*1000;
while (((new java.util.Date()).getTime()<stop)&&(!w.done)) {}
//wait for paint finished, max 10 sec.
//never exit from loop because of w.done==true!!!!!!
//here I execute method_that_processes_data_employing_some_seconds();
}
public window()
{
super();
setSize(100,100);
setLocation(200,200);
Button b=new Button("Push");
done a=new done();
b.addActionListener(a);
add("Center",b);
addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{System.exit(0);}
}
);
setVisible(true);
}
//inner class
class done implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
removeAll();
write wait=new write(100,100,"Wait");
add("Center",wait);
wait.repaint();
validate();
repaint();
work(wait);
removeAll();
write done=new write(100,100,"Done");
add("Center",done);
validate();
repaint();
}
}
}
//Component with Image; here I insert a simple String
class write extends Canvas
{
private String phrase;
public boolean done;
public write(int dimx,int dimy,String phrase)
{
super();
setSize(dimx,dimy);
this.phrase=phrase;
done=false;
}
public void paint(Graphics g)
{
g.drawString(phrase,20,30);
done=true;
System.out.println("paint finished: writed "+phrase);
}
}
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24