Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners searching for strings in a file
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


NIJIN P P
searching for strings in a file
1 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners


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


Advertisement
View Answers

August 20, 2011 at 3:43 PM


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



Related Tutorials/Questions & Answers:
searching for strings in a file
searching for strings in a file  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.
file searching
file searching  i need a prog for searching inside a text file after evry 1 min to find does it hav any new entry
Advertisements
searching inside a file for details
searching inside a file for details  i created a file with name,country,state etc...when i'm searching for the name, i have to get other details like country,state etc...please do help
Searching a word file on server in JSP - JSP-Servlet
Searching a word file on server in JSP  Seacrhing a word file on server side using JSP. I am Apache Tomcat Server. Please help me Sir
searching a text string in file - Java Beginners
searching a text string in file  code to match a string in a file that is already mentioned in java code.if the string matches any part of a string that whole string is printed
strings
strings  difference between the strings in java and c
strings
strings  write a program in java to accept two strings as command line arguments and perform the following operations-: 1) compare the strings 2... is an example which accept two strings as command line arguments and perform
Strings
will contain strings which is separated by ",". From the main method invoke
strings
strings   read sentence and convert all the word into capital case like camelcase   Hi Friend, Try the following code: import java.util.*; class ConvertWordsIntoUpperCase { public static String toCamelCase(String
searching books
searching books  how to write a code for searching books in a library through jsp
searching technique
searching technique  Hi, i need any searching technique in java to search the data and give the all possible data by links
searching problem
searching problem  how we can make a code in core java for searching in hard disk? i have to make an antivirus as my minor project , so i have need this type code to search the virus in hard disk
searching problem
searching problem  how we can make a code in core java for searching in hard disk? i have to make an antivirus as my minor project , so i have need this type code to search the virus in hard disk
searching string
searching string   how to write a program for searching a string   Hi Friend, Try this: import java.util.*; class SearchString{ public static void main(String[] args){ Scanner input=new Scanner(System.in
searching the data
searching the data  respected sir , i am making the desktop application , so how can i search the data which are stored in the mysql databses through click the button and display in jtable through netbeans dynamically
Sorting and Searching
); { System.out.println("Error reading from file"); } } } } System.out.print("Invalid
Java Sorting and Searching
Java Sorting and Searching   If anyone could help me with this I would be really thankful! Write a program that stores the names of these artists... introduced in the lecture and modify it so that it handles strings, rather than integers
Strings in PHP
Strings in PHP  Hi, I am beginners and want to know about strings in PHP and different ways to print a string. Can someone help me in this regards?   Following tutorials will help you in details about strings in PHP
strings concatnation
strings concatnation  in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic
strings in java
strings in java  please explain me the flow of this program..not able to execute correctly n wats the use of clone public class Strclone { public static void main(String args[]) { String s=new String("a"); String s1
strings 20june
strings 20june  please explain me the flow of this program..not able to execute correctly n wats the use of clone public class Strclone { public static void main(String args[]) { String s=new String("a"); String s1 = "Hello
Searching for Code - JSP-Servlet
JSP, Servlet Searching for Code  Hi, i am looking for a jsp servlet code examples for the search function in my application.Thanks
Advertisements
 

 

 

DMCA.com