File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Sun java tutorial swing addActionListener code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sun java tutorial swing addActionListener code" Watch "Sun java tutorial swing addActionListener code" New topic
Author

Sun java tutorial swing addActionListener code

Tom Never
Greenhorn

Joined: Jan 11, 2006
Posts: 7
I am reading the sun tutorial and I don't see in this code where the 2nd addActionListener is in the code for both the enter and button. They write in the tutorial:

We want to perform the conversion when the user clicks the button or presses Enter in the text field. To do so, we add an action event listener to the convertTemp button and tempCelsius text field.

convertTemp.addActionListener(this);
tempCelsius.addActionListener(this);
...


But I don't see it in the code. It works, for both button and enter, but where is it in the code? Thanks, Tom

I]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

You're not going crazy; the writeup doesn't match the code. In the code, they only add the event handler to the button, not to the JTextField. But they also do this:

converterFrame.getRootPane().setDefaultButton(convertTemp);

That ensures that any unhandled "Enter" presses will filter up to the RootPane, which will dispatch them as ActionEvents to the given default button. Note how when you press Enter, the button flashes. So the JTextField isn't handling the Enter presses at all!

Maybe they wrote it one way, changed it, and didn't update the description!


[Jess in Action][AskingGoodQuestions]
Tom Never
Greenhorn

Joined: Jan 11, 2006
Posts: 7
Thanks. I'm still learning my way around packages/api documentation. It's amazing what they don't tell you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sun java tutorial swing addActionListener code
 
Similar Threads
External files
Getting "Type expected" when trying to compile applet
Creating a simple browser
another .ttf question
Creating and showing JFrame from another JFrame