This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about ActionListener

 
Yanxin Zhao
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
 
J Virumbi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic