• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI Help please

 
Christopher Docherty
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is my first post on the ranch, and i am hoping someone can help me out.

I am trying to code a GUI that will populate the blank JTextFields, from another class.

The GUI is fine in that it can display the various buttons, labels and text fields, however i cannot figure out how to fill the text fields.

eg. To fill in the name field in the GUI from a completed questionnaire.


I hope I have made sense, and thanks for taking time to read.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Christopher!

I'm moving this to the Swing / JFC / AWT forum...
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there are a couple of ways to access variables from other classes. This really isn't GUI specific as you would do this in almost any Java program.

The first way, and probably the prefered way, is to create your class with getter methods for the values you need. Kind of like a Javabean, but as this Class probably does more than store data..



Then in your other class you would simply do something like



A less coded way of doing the same thing would be to store all your answers in some sort of a Collection class instead of individual Strings.

The other way would be to declare all your variables public and just access them like completedQuestionaire.answer1;

And yet another way is to declare all the variables public static and then you don't even need an instance of your CompletedQuestionaire class. All you have to do is specify the class name and the variable like CompletedQuestionaire.answer1;

Ok, so now that I have throughouly confused you...If you want to try one of those options out and then when you are having problems with the code, you can post the code here and we can help you better.
 
Christopher Docherty
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your time.

I will have a go and let you know how i get on.

Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic