Share on Google+Share on Google+

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










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 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
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads