• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timer and Textfield

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a frame with question and answer textfields. Timer gets executed for every 30 seconds and a new frame will be displayed. But when the user enters an answer the timer should stop. How to acheive this?

I tried by using getSource() method like
public class TimerListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object source = event.getSource();
if(source instanceOf JTextField) {
timer.stop();
}
}
}

But its not working. Here the source is coming as timer source but not as textfield source. So how to get the source of a textfield in the timerlisterner class?
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getSource() considered harmful:
except in rare occasions if you want to use getSource() you have
an architectural problem ..

is this possible? :
MyTextField extends TextField implements ActionListener
 
reply
    Bookmark Topic Watch Topic
  • New Topic