Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: How to make class method wait for user input from gui

  1. #1
    Junior Member
    Join Date
    Feb 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Hello,

    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?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to make class method wait for user input from gui

    so I want the paging() method to wait until the user clicks a button.
    Don't start the method until the user presses the button. That is the natural way that GUI works.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to make class method wait for user input from gui

    There is another button that starts the paging() method, but then it waits for user input.
    If the user presses next page then it retrieves the next 10 results, prints them and asks the user again if he wants to go to previous, next etc

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to make class method wait for user input from gui

    asks the user again
    How and where does the program ask the user any question?
    Is there a prompt in a small window?
    Is there a message written to a text field in the GUI?
    Or somewhere else?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to make class method wait for user input from gui

    There is a textfield in the GUI
    Last edited by blueberry123; February 20th, 2022 at 06:16 PM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to make class method wait for user input from gui

    Is the paging method running on its own thread?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to make class method wait for user input from gui

    Yes

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to make class method wait for user input from gui

    One way to coordinate between threads is to us the CountDownLatch class. There is a sample program in the API doc for the class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Filling an array with user input and a method
    By FlyingGvirus in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 4th, 2014, 03:26 PM
  2. BEGINNER: Asking user input from java/class to jsp
    By fmjnax in forum JavaServer Pages: JSP & JSTL
    Replies: 9
    Last Post: October 29th, 2013, 11:50 PM
  3. How to repaint() a class in a JFrame, with a JTextfield user input
    By DANGEROUSSCION in forum Object Oriented Programming
    Replies: 1
    Last Post: March 23rd, 2013, 03:06 PM
  4. Asking for user input in the main method?
    By HeroProtagonist in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 19th, 2012, 07:00 AM
  5. [SOLVED] Help with getting user input for my factorial method
    By u-will-neva-no in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 4th, 2011, 01:24 PM