-
use while loop in jframe
i am writting a program need to render new object into the scene graph continuously
the program is connect to other program and use a while loop to read message from it, so the program know which object need to render into the scene graph next and renew the frame
the problem is the frame only visible after the method is end
if the while loop dont end, the frame show nothing
so... how can i solve this problem? is it need to use other method to renew the frame instead of using while loop?
-
You question is hard to understand, especially without an SSCCE that demonstrates the problem. What I can guess is that you have a loop that is tying up the EDT...place this work in another Thread or use a SwingWorker.
-
here is my code
it is expected to get new object info in the while loop and renew the scene geaph
but the frame don't show anything, unless i remove the while loop
Code:
public void init() {
... snip
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add("Center", c);
JPanel p = new JPanel();
p.add(forward);
p.add(backward);
p.add(left);
p.add(right);
p.add(up);
p.add(down);
p.add(quit);
add("North", p);
universe = new SimpleUniverse(c);
... snip
while(true){
msg = s.readLine();
if(msg.equals("."))
{
con.sendmessage(msg);
con.readmessage();
System.out.println("client got:" + msg);
break;
}
con.sendmessage(msg);
con.readmessage();
System.out.println("client got:" + msg);
}
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
-
Read my post above...place long running tasks in a Thread or SwingWorker
-
so... i should use SwingWorker to help?