• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
N Hakim
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
N Hakim
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply. Can you show an example how to use the setter and constructor method?
 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic