Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5964993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:32:00+00:00 2026-05-22T19:32:00+00:00

Ok so i have made a search function using scanner in console, but i

  • 0

Ok so i have made a search function using scanner in console, but i would now like to create a search function from my GUI. When text is entered into a JTextFieldand JButton is clicked i would like a method which would search my text file line by line until it finds the the searched for criteria and prints it into a JOptionPane.

Data in text file is formatted as follows:

what would be the best way to go about this?

Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:32:01+00:00Added an answer on May 22, 2026 at 7:32 pm

    You already have the search method, so add an action listener to your button, that will call your method, something like:

    myButton.addActionListener(new ActionListener() {
    
        public void actionPerformed(ActionEvent e) {
            String whatToSearch = myTextField.getText();
            String result = yourSearchMethod(whatToSearch);
            // use the fitting method of JOptionPane to display the result
        }
    }
    

    Seeing your update, you better split the search function, so it will receive the search criteria as an input, something like:

    public class SearchProp {
         public String getSearchCriteria()
         {
                Scanner user = new Scanner(System.in);
                System.out.println();
                System.out.println();
                System.out.println("Please enter your Search: ");
                input = user.next();
         }
    
         public void Search(String input) throws FileNotFoundException{
            try{
                String details, id, line;
                int count;
                Scanner housenumber = new Scanner(new File("writeto.txt"));
                while(housenumber.hasNext())
                {
                    id = housenumber.next();
                    line = housenumber.nextLine();
                    if(input.equals(id))
                    {
                        JOptionPane.showMessageDialog(null,id + line );
                        break;
                    }
                    if(!housenumber.hasNext())      
                         System.out.println("No Properties with this criteria");
                }
           }
    
           catch(IOException e)
           {
                System.out.print("File failure");
           }
       }
    }
    

    Now, when you run it from console, you first call the getSearchCriteria and then Search. The input of Search is the return value of getSearchCriteria. In your GUI you only need to call search (with the text from the JTextField as an input).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to implement binary search tree but I think I have made
I have been using jqGrid for a few months now, and I have made
I have been playing around a bit with a fairly simple, home-made search engine,
I have made a SVG image, or more like mini application, for viewing graphs
I have made a new windows service which works fine using barebone code (just
I have made a class which a form can inherit from and it handles
I have made an application (for my self) for feeds reading, using SyndicationFeed ,
Recently I made a utilities function like: // T2CA #include ATLCONV.H std::string Utils::CString2String(const CString&
I have a function that searches for a string inside a text file. I
I have this 'web service' I made that when accessed: http://192.168.0.1/api/v1/search/?query=thequery returns a JSON

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.