Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes Question about ActionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Question about ActionListener" Watch "Question about ActionListener" New topic

Question about ActionListener

Yanxin Zhao
Ranch Hand

Joined: May 05, 2004
Posts: 65
Hi: everyone
I got a problem about ActionListener.
I want to use a button to control a JTextField in another class. but I am not sure how to do it. I do not know what's problem about my code, but I can not implement what I want to do.
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342

To my thinking the easiest way to get this working would be to have the GUI stuff in one class. So I've defined a MyGUI class, which is controlled by a MyGUIApp class.

Hope this helps a little. It may not be the most elegant solution, but it works

SCJP 1.4,
J Virumbi

Joined: Nov 15, 2003
Posts: 3
Look at ur this line:

new Test4().tf.setText("HelloWorld");

The "new" keyword will be creating a new Instance of Test4 class for every click on the button. Offcourse you can not see the new GUIs bcoz u are not calling builfGUI method.

If U want set a "hello World" text in the textfield for each button click, U have to do it on the existing instance of Test4 which has built ur GUI.

I have never coded in AWT. I can solve the problem but It may not be the right practise.

Check the books coz u missed the basics.

Yanxin Zhao
Ranch Hand

Joined: May 05, 2004
Posts: 65
Thanks so much for your reply, Ben and J.
J, you are right, I did not realized that before. thanks so much for you reply my question so fast, Ben and J. you are save me much time. really thanks.
Don't get me started about those stupid light bulbs.
subject: Question about ActionListener
Similar Threads
help me!!
Placing a component at center both vertically and horizontally
Cant get BoxLayout to work right !!
Accessing dynamic Components