
how can i search of a person and display the other details associated with the name using java gui window?

import java.util.ArrayList;
import javax.swing.*;
import java.awt.event.*;
class Book{
int bookid;
String title;
String author;
Book(int bookid,String title,String author){
this.bookid=bookid;
this.title=title;
this.author=author;
}
public void setBookId(int bookid){
this.bookid=bookid;
}
public int getBookId(){
return bookid;
}
public void setTitle(String title){
this.title=title;
}
public String getTitle(){
return title;
}
public void setAuthor(String author){
this.author=author;
}
public String getAuthor(){
return author;
}
}
public class BookInformation{
public static void main(String[]args){
final ArrayList<Book> list=new ArrayList<Book>();
list.add(new Book(1111,"Godan","Munshi Premchand"));
list.add(new Book(2222,"My Experiment with Truth","Mahatma Gandhi"));
list.add(new Book(3333,"Gitanjali","Rabindra Nath Tagore"));
list.add(new Book(4444,"Malgudi Days","R K Naraynan"));
list.add(new Book(5555,"Jayadev","GeetGovind"));
JFrame f=new JFrame("Search");
f.setLayout(null);
JLabel label1=new JLabel("Enter book id ");
final JLabel label2=new JLabel("Title ");
final JLabel label3=new JLabel("Author ");
final JTextField text1=new JTextField(20);
final JTextField text2=new JTextField(20);
final JTextField text3=new JTextField(20);
JButton b=new JButton("Search");
label1.setBounds(10,10,100,20);
text1.setBounds(120,10,200,20);
b.setBounds(350,10,100,20);
label2.setBounds(10,40,100,20);
text2.setBounds(120,40,200,20);
label3.setBounds(10,70,100,20);
text3.setBounds(120,70,200,20);
label2.setVisible(false);
text2.setVisible(false);
label3.setVisible(false);
text3.setVisible(false);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int ide=Integer.parseInt(text1.getText());
if(!text1.getText().equals(" ")){
label2.setVisible(true);
text2.setVisible(true);
label3.setVisible(true);
text3.setVisible(true);
for(Book data: list){
if(data.getBookId()==ide){
text2.setText(data.getTitle());
text3.setText(data.getAuthor());
}
}
}
}
});
f.add(label1);
f.add(text1);
f.add(label2);
f.add(text2);
f.add(label3);
f.add(text3);
f.add(b);
f.setVisible(true);
f.setSize(500,200);
}
}
For more information, visit the following link:
http://www.roseindia.net/java/example/java/swing/addeditanddeleteemployee_inf.shtml
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.