Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 27th, 2006, 04:49 AM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 3
Timer class ?

im using netbeans and im trying to tell the timer to start only problem is ..


netbeans doesn't recognize two member functions in the Timer library timer.start() and timer.setDelay()
Code:
private float converTics(float a)
{
   //converts entered miliseconds into seconds
   float b;
   b = a * 1000;
   return b;
}
// set the delay to the specified seconds
timer.setDelay(converTics(speed_tics));
//start the timer
timer.start();


are setDelay or start functions in the library at all ? or do i need to define it myself ? the member functions notify() and schedule are available, can i use those to do my bidding ?

Reply With Quote
  #2  
Old October 29th, 2006, 05:51 AM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 3
i put the

Code:
clock = new Timer(1, new EventHandler());


....
....
....
....
....
if (a == b)
{
    
  field_one.setText(" some text " );
try 
   {
     clock.wait(10);
   } 
     catch (InterruptedException ex) 
   {
     ex.printStackTrace();
   }

 clock.notifyAll();
field_one.setText(" ");

}

though i keep getting a
Quote:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.wait(Native Method)
at race$EventHandler.actionPerformed(race.java:255)
at javax.swing.Timer.fireActionPerformed(Timer.java:2 71)
at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 461)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)

error when the conditions are met, not sure what that error means, im trying to have the timer to stop running for 10 secs then clear the status label then continue on till that condition is met again , any suggestions ?

Reply With Quote
  #3  
Old November 3rd, 2006, 10:39 PM
daniel_g daniel_g is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 60 daniel_g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 3 m 50 sec
Reputation Power: 3
Never seen that exception before.
Instead of clock.wait() could you use Thread.sleep()?
Maybe someone knows better, but I think java is telling you that you don't own the Timer class?
http://java.sun.com/j2se/1.4.2/docs...ect.html#wait()
http://java.sun.com/j2se/1.4.2/docs...tml#sleep(long)

Reply With Quote
  #4  
Old November 6th, 2006, 03:59 PM
fizker fizker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: denmark
Posts: 42 fizker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 18 sec
Reputation Power: 5
Send a message via MSN to fizker
A timer works by sending an event when the time runs out, not by halting program-flow as it seems you think.
You need to handle this event in an appropriate listener (see below).

Try this code and report back .
Code:
if (a == b)
{
    
field_one.setText(" some text " );

Timer timer = new Timer(
	10*1000, /* to get it as seconds */
	new ActionListener() { /* the actionListener which handles the timer */
		public void actionPerformed(ActionEvent e) {
			field_one.setText(" ");
		}
	}
);
timer.setRepeats(false); /* we only want to fire one event */
timer.start();

}

Both the ActionListener interface and the ActionEvent class can be found in the java.awt.event package.
__________________
Benjamin Horsleben
horsleben.com/benjamin
Don't blame malice for what stupidity can explain

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Timer class ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway