'How to make class method wait for user input from gui

I have a program with a gui and a different class named Search with a static method named paging(). This paging method retrieves some results and shows them using pagination, so, it prints first e.x 10 results and then asks the user if he wants to continue to the next page, previous, quit or jump to a page. I have buttons for previous, next page etc. on the gui, so I want the paging() method to wait until the user clicks a button. What is the right way to do this?

public Gui extends JFrame{

JButton Next;
JButton Previous;
JTextField textField;

public static void Main(){
 
  }
}

public class Search(){
   public static void paging(){
        int results; // the results returned for the search 
        int itempsPerPage = 10;
        
        while(true){
            Console.WriteLine("Press (n)ext page, (p)revious page, 
                                (q)uit");
          BufferedReader reader = new BufferedReader(
                                  new InputStreamReader(System.in));  
         String input = reader.readLine();
         if (input.charAt(0)=='q') {
                 stopSearch = true;
                 break;
         }
         if(input.charAt(0) == 'p'){
           // Go to previous page
             break;
         }
         else if(input.charAt(0) == 'n'){
            //Go to next page
             break;
            }  
         }
    }
}

This is how it was written initially as a console program



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source