Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

First time using GUI and having some issues  RSS feed

 
Akira belliveau
Greenhorn
Posts: 25
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first time using GUI and I was wondering what I'm doing wrong. I've been trying to read about it and look at other posts and I can't seem to find my problem. When ever I just try to run my project the window pops up but when I click calculate the whole thing just freezes and i can't exit out. Can you guys give me any tips/advice?

 
Mohammad Shams Tabrez
Greenhorn
Posts: 4
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am prty new in java also....but which portion of your GUI have you written ???
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lines 205 to 257 show a while loop: while(runAgain.equals("y") { ... } . In that while loop you never change the value of runAgain, so the loop runs forever. The loop also runs inside the Event Dispatch Thread (the GUI thread) which means you can't interact with the UI anymore - the application is hung.

Solution: Change the value of runAgain at some point to make sure the loop ends.
Also: Any long-running processes (such as a loop that may run indefinitely) should not be done in the EDT because it will block the UI. You should move it to a background thread. Look up SwingWorker and SwingUtilities for some helpful tools on getting tasks to run outside the EDT.
 
Akira belliveau
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Steve

Do you think I would be able to take out the while loop as a whole because there really isn't a point of having a while loop to ask the user if they would like to run again since they can just press calculate again?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akira belliveau wrote:Do you think I would be able to take out the while loop as a whole because there really isn't a point of having a while loop to ask the user if they would like to run again since they can just press calculate again?

I don't know, it is your specification. Why did you put the loop in there? Did is serve an expected purpose? Do you think that purpose is served without the loop?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!