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
You already have the search method, so add an action listener to your button, that will call your method, something like:
Seeing your update, you better split the search function, so it will receive the search criteria as an input, something like:
Now, when you run it from console, you first call the
getSearchCriteriaand thenSearch. The input ofSearchis the return value ofgetSearchCriteria. In your GUI you only need to call search (with the text from the JTextField as an input).