• Post Reply Bookmark Topic Watch Topic
  • New Topic

Search Method . Passing values Problem  RSS feed

 
chopo carlos
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I need some help i am doing a Simple GUI. ( My first GUI)
It has two Fields Name , Age.
I want to create a search button, where you can search by name ( Very Simple ) displays the name and age if found.
I have stored these values ArrayList<Person> myarraylist, and i have a person class with two varibles Name and age.
My problem is I created a method that takes and Object ( Person ), but the value that i get from the GUI is a string.

String n = textName.getText();

Is there anyway i can pass this value to my method???

public void search(Person p).

or how can i search the arraylist ???

Thank you.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you create a Person object? Does it have a constructor or setters that take a String?
 
chopo carlos
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

yes i have a constructor in person class


i get the values from the GUI and added to the array.

String thename = textname.getText();
int thename = Integer.parseInt(textage.getText());




myarraylist.add(new Person(thename,theage));





 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
name = theid;

That line calls the variable theid, and you have no variable by that name. It would appear you have copied something wrongly. Please always post working code, preferably using copy-and-paste.
 
chopo carlos
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there


Yes i made mistake sorry about that.


 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies accepted
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just iterate through the List and compare the names. If it matches return that name.

I've edited your openings post and removed a lot of unnecessary white space.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!