Results 1 to 5 of 5
  1. #1
    vinci is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default 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?
    Last edited by vinci; 02-09-2011 at 03:11 PM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    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.

  3. #3
    vinci is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default

    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

    Java 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();
            }
        }

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    Read my post above...place long running tasks in a Thread or SwingWorker

  5. #5
    vinci is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Replies: 5
    Last Post: 06-14-2010, 06:10 PM
  2. JFrame from a JFrame in project
    By anah in forum AWT / Swing
    Replies: 2
    Last Post: 04-19-2010, 06:20 PM
  3. Replies: 6
    Last Post: 04-12-2010, 11:33 AM
  4. Passing data from one JFrame to another JFrame
    By tarami in forum New To Java
    Replies: 3
    Last Post: 08-06-2009, 05:44 PM
  5. Replies: 4
    Last Post: 04-22-2009, 11:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •