This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Java Address Book : How to get jtextfield text from another class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java Address Book : How to get jtextfield text from another class?" Watch "Java Address Book : How to get jtextfield text from another class?" New topic
Author

Java Address Book : How to get jtextfield text from another class?

N Hakim
Greenhorn

Joined: Aug 01, 2013
Posts: 4
Im new to Java and Im doing a address book project. I have 2 classes, the GUI and AddGUI. I want the user input at the AddGUI to show in the jtextfield of the GUI. How do I do it?

GUI class:


AddGUI class:


Thanks.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

just a quick reply.
there are two ways.
make the GUI textbox not private. then you can access it from the other class //not recommended
use a setter method in the main class.
either way the helper class will need a reference to the main class.
passed to it either in it's constructor, or a method.
sorry i didn't actually read your code.


SCJP
Visit my download page
N Hakim
Greenhorn

Joined: Aug 01, 2013
Posts: 4
Thank you for the reply. Can you show an example how to use the setter and constructor method?
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

yes i can...hold on...
in fact i demonstrate both methods. i had a compelling reason to make DrawingArea not private.
from the main class:

from the DrawingArea class

you will want to use a String instead of a boolean, but this should give you the idea
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Address Book : How to get jtextfield text from another class?
 
Similar Threads
Focus problem using JOptionPane.showInternalMessageDialog
Componet Allignment
2D Array Help
ActionListener problems
I enter a password into a JPasswordField, but nothing happens??