-
Why is a GUI display stuck on the first actionperformed state
Could somebody please suggest me how a GUI interface displays only the first and last program running states.
The programe is running ok and the variables for the GUI display updating ok but it doesn't display it.
When I press one button, it seems stuck on the pressed states and doesn't display how the program runs(I want it) and the pressed button is kept pressed state so I coudn't do any other button pressed action. It will keep like this until the last program running step and then it shows the last state ok.
Thanks.
-
The process you want to monitor has to be running in a separate and normal-priority
thread. If you run in in the main program thread (the same as the GUI) then the
program won't have any "spare time" to update the GUI.
eschew obfuscation
-
Thanks a lot, sjalle.
My mind is a mess now and cannot figure out exactly how to change it.
I made my program like this:
main()
{
....
initialize GUI
}
OneThread()
{
....
updateGUI()
}
GUI()
{
....
wait user action;
run, pause, resume and stop thread
}
The progarm would take most of the time in the thread.
Could you please suggest me how I should change it. Thanks very much.
-
Just create and initiate the GUI as usual, no threading.
Then make your GUI (frame) implements Runnable like
Code:
public class MyAppFrame extends JFrame implements Runnable {
Thread myThread=null;
boolean doSleep=false;
boolean doStop=false;
.
.
// the "Start" button event handler
public void actionPerformed (ActionEvent ae) {
myThread=new Thread(this);
myThread.start();
}
// the thread
public void run() {
// invoke the method that starts the processing
myProcess();
}
}
I assume your process is controlled by a loop. This loop must check the two
flags, doSleep and doStop at each iteration and the flags must be controlled
by two buttons, "Pause/Resume" and "Stop". When doSleep == true you
put the thread to sleep for a second and keep on doing that until doSleep==false.
When doStop==true the myProcess method shall return and the program
control will leave the run method, and the thread will die.
eschew obfuscation
-
Thanks very much, sjalle.
Now it could keep updating and the pause and stop action work.
It seems that I can only do the thread operations after button pressed, otherwise, the program will be stuck. But I would need something like reset the system and also the GUI.
The same with the "stop" action part I can only make it work when
I use myThread.stop(); Otherwise it will be the same stuck.
And also I will be appreciated if you could explain a bit why to make a GUI a thread will keep updating? (a high priority? or what?)
Thanks a lot.
Sorry I seem stuck on every step and need suggestions on every process.
-
-
Thank you very much, sjalle. It's very kind of you.
The thread.interrupt() helps it work. I've got those button actions work finally.
I tried to use the try/catch in the process, (I think it makes everything clear)but it said there is no interruptException throw in the process. I used "if" to check the flags in every iterator and made them work. (looks very inefficient, though)
I used the thread.stop() operation (though it is said Deprecated)
Thanks again. It's good to have you here.
Similar Threads
-
Replies: 0
Last Post: 05-29-2005, 08:54 AM
-
Replies: 0
Last Post: 02-11-2003, 01:10 AM
-
By Allen Pitts in forum XML
Replies: 0
Last Post: 10-31-2002, 03:02 PM
-
By Ariel Azia in forum ASP.NET
Replies: 3
Last Post: 08-02-2000, 01:10 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks