Results 1 to 3 of 3
- 04-30-2012, 12:00 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 12
- Rep Power
- 0
JFrame is blank until an unrelated while loop in another class finishes...
I am completely stumped on how my computer is doing this. Basically I'm declaring a new frame, like so
Here are the related functions being called:Java Code:view2.agentWindow(type); view2.stopActionListener(this); model2.addAgent(model, 214, 2, 5, "deposit");
Java Code:public void agentWindow(String name) { JPanel panel = new JPanel(); frame = new JFrame(name); frame.pack(); //set up frame size and location Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width; frame.setSize(screenWidth / 7, screenHeight / 7); frame.setLocation(screenWidth / 4, screenHeight / 4); //Creates the text fields display1 = new JTextField("", 20); display1.setEditable(false); panel.add(display1); display2 = new JTextField("", 20); display2.setEditable(false); panel.add(display2); state = new JTextField("Running...", 20); state.setEditable(false); panel.add(state); // Creates the buttons stagent = new JButton("Stop Agent"); panel.add(stagent); dismiss = new JButton("Dismiss"); panel.add(dismiss); frame.add(panel); frame.setVisible(true); }Now what happens is that until the while loop in the model is finished, the new frame just displays as "deposit" with no text fields or buttons. Once the loop is finished, the things appear. It's quite irritating because my loop breaker is supposed to be one of the buttons that aren't appearing.Java Code:public void addAgent(Account model, int aid, long ops, double amount, String type) { run = true; try { while (run==true) { run = false; if(type.equals("withdraw")) { model.setValue(model.getValue()-amount); } else if (type.equals("deposit")) { model.setValue(model.getValue()+amount); } Thread.sleep(1000 * ops); } } catch (InterruptedException e) { e.printStackTrace(); } }
Any ideas as to why this is happening?
- 04-30-2012, 01:19 PM #2
Re: JFrame is blank until an unrelated while loop in another class finishes...
If the loop is running on the GUI's thread, then the GUI can not be updated until you return the thread for it to execute on.
You need to give the GUI code back its thread every time you want something to change and be visible, otherwise nothing is done until it gets control again.If you don't understand my response, don't ignore it, ask a question.
- 04-30-2012, 03:29 PM #3
Re: JFrame is blank until an unrelated while loop in another class finishes...
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Assignment of blank value of input variable after the first loop iteration
By buggedup in forum New To JavaReplies: 5Last Post: 04-17-2011, 11:05 PM -
use while loop in jframe
By vinci in forum New To JavaReplies: 4Last Post: 02-09-2011, 03:28 PM -
Getting unrelated input from several text fields
By starexecutive in forum New To JavaReplies: 1Last Post: 01-16-2011, 07:04 PM -
how to get value from unrelated class struts-hibernate
By arsmith in forum Web FrameworksReplies: 0Last Post: 12-02-2009, 05:29 PM -
problem in accessing array values of one class in to jframe class
By cenafu in forum AWT / SwingReplies: 8Last Post: 03-21-2009, 09:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks