searching for strings in a file

Ads

 
 
 

Share on Google+Share on Google+

NIJIN P P
searching for strings in a file
1 Answer(s)      5 years and 9 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?

Ads
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


Ads









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
searching the string in a paragraph?
searching the string in a paragraph?  how to search a string in a paragraph and display the corresponding line number and position of a string in java
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
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
Tutorials   
Java Spring Hibernate Struts Training ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java

Ads

 
Advertisement null

Ads