Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-23-2004, 11:07 PM
|
#1
|
Member
Registered: Feb 2003
Location: Hawaii
Distribution: Debian
Posts: 130
Rep:
|
How do you stop this particular timer? JAVA
This timer triggers a progress bar. The goal is to stop the timer (and therefore the progress bar) when a label changes its text.
However, the timer goes on for ages and the progress bar keeps going until it reaches 100%. The timer never stops, it just that the progress bar can't go any further.
In other words,
1. How do you stop the timer below?
2. How do you make this timer below to listen to other events such as threads terminated or label text change?
Feel free to tweak around the code below so I can see what you mean. I learn by example.
Thanks in advance,
Code:
int i = 0 ;
public void timer2 ()
{
Timer t2 = new Timer ( 10000, new ActionListener () //10 seconds
{
public void actionPerformed ( ActionEvent event )
{
progressBar.setValue ( i ) ;
progressBar.setStringPainted ( true ) ;
i++ ;
}
} ) ;
t2.start () ;
if ( lblStatus.getText ().equals ( "CD succesfully created" ) ) {
i = 100 ;
progressBar.setValue ( i ) ;
progressBar.setStringPainted ( true ) ;
t2.stop () ;
}
}
|
|
|
07-24-2004, 12:33 AM
|
#2
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,795
|
Is your label already set to "CD succesfully created" (typo here) when you start the timer ?
|
|
|
07-24-2004, 01:29 AM
|
#3
|
Member
Registered: Feb 2003
Location: Hawaii
Distribution: Debian
Posts: 130
Original Poster
Rep:
|
set to "status"
No, it isn't. The label is by default set to "status".
Then when the thread that burns the CD is all done, it changes the label from "status" to "CD succesfully created".
The thread executes ok, the thread finishes ok, and the label displays "CD succesfully created" ok.
However, the timer doesn't "see" the label I guess.
Any ideas?
Last edited by randomx; 07-24-2004 at 01:30 AM.
|
|
|
07-24-2004, 03:05 AM
|
#4
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,795
|
You check the label only once, and at a time when its value is "status", so it always fails.
You should do you test periodically to give it a chance !
PS: succesfully should be spelled successfully
|
|
|
07-24-2004, 05:36 AM
|
#5
|
Member
Registered: Sep 2003
Location: //home/sweden
Distribution: RedHat 9, Fedora Core 1
Posts: 360
Rep:
|
Quote:
Originally posted by jlliagre
You check the label only once, and at a time when its value is "status", so it always fails.
You should do you test periodically to give it a chance !
PS: succesfully should be spelled successfully
|
That also apears to be the issue to me. After you start the timer you check the label then the thread timer2 completes, while the t2 thread continues to execute. Try setting up a 2nd timer or thread to check the label, and then stop itself and the other thread when it is done.
|
|
|
All times are GMT -5. The time now is 02:48 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|