• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic GUI problem :(

 
Waria Ahmed
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just creating a test GUI program, I have got a text field for first name and a text field for last name. In my JFrame class I am trying to take the input from firstNameTextField and in return print out the last name into the lastNameTextField. This is my code for the actionPerformed�



Basically if the text in the firstText ( variable name for my textfield) matches the first name of the person in the array. Then I want to print the second name in the text field. However I am having problems getting the text from first text field.

Can anyone shed any light on this matter please? Am I doing anything wrong?

Thanks
 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you create a method "firstTextequals" or is there supposed to be a dot in there somewhere? Please be careful to Post Real Code.
Assuming that you wanted to write "firstText.equals", exactly what are you comparing to the values in the array?
 
Waria Ahmed
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i missed a . there but it still doesnt work.

Basically "firstText" is the variable name for the textfield, which the user types into. And whenever the user presses the search button, I want the program to take what the user typed into "firstText" and search through the array looking to see if it matches any people in array.

If it matches, I want the second name of the person to be displayed in "lastText" textfield.

I know my explanation isnt the best, so please feel free to ask further questions.

Thanks
 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Waria Ahmed:

Basically "firstText" is the variable name for the textfield,


OK. So you have a textfield named "firstText". In the following comparison, what is being compared:


Hint: what is the type of firstText? What does the array contain? Can they ever be equal?
 
Waria Ahmed
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im assuming the firstText is a String, and getFirstName returns a String?

i get the NullPointerException when i run the program.
 
Waria Ahmed
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the full program if it helps...



And Person class...

 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Waria Ahmed:
Im assuming the firstText is a String, and getFirstName returns a String?


Your assumption is wrong. Your code says:
 
Waria Ahmed
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OHHHH Ok.... I get you.

How do I store the input from user as firstText?
 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be in there if the user has typed something in.
It is a good idea to print out the values you are comparing when things aren't working the way you think they should.
 
Waria Ahmed
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the error I get when i type something and press "search"

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at uni.NewJFrame.searchButtonActionPerformed(NewJFrame.java:104)
at uni.NewJFrame.access$100(NewJFrame.java:16)
at uni.NewJFrame$2.actionPerformed(NewJFrame.java:53)
 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a good idea to print out the values you are comparing when things aren't working the way you think they should.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic