LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 07-23-2004, 11:07 PM   #1
randomx
Member
 
Registered: Feb 2003
Location: Hawaii
Distribution: Debian
Posts: 130

Rep: Reputation: 16
Question 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 () ;
    }

  }
 
Old 07-24-2004, 12:33 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,795

Rep: Reputation: 496Reputation: 496Reputation: 496Reputation: 496Reputation: 496
Is your label already set to "CD succesfully created" (typo here) when you start the timer ?
 
Old 07-24-2004, 01:29 AM   #3
randomx
Member
 
Registered: Feb 2003
Location: Hawaii
Distribution: Debian
Posts: 130

Original Poster
Rep: Reputation: 16
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.
 
Old 07-24-2004, 03:05 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,795

Rep: Reputation: 496Reputation: 496Reputation: 496Reputation: 496Reputation: 496
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
 
Old 07-24-2004, 05:36 AM   #5
Guru3
Member
 
Registered: Sep 2003
Location: //home/sweden
Distribution: RedHat 9, Fedora Core 1
Posts: 360

Rep: Reputation: 31
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
some reason java stop working Paxmaster Linux - Software 1 01-12-2005 10:35 PM
Stop java program(threaded program..should end cleanly) rmanocha Programming 4 11-09-2004 09:36 AM
Java Timer alaios Programming 2 05-24-2004 01:39 PM
Java Timer alaios Programming 3 05-24-2004 11:52 AM
java timer mcshen Programming 11 03-30-2004 04:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration