Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't try to mix Scanner input with a Swing GUI. Your problem is by doing this, you're tying up the Swing event thread, freezing your GUI as your program awaits Scanner input. </p> <p>Better to get your input through the GUI, optimally through JTextComponents such as JTextFields, or if you must, via a JOptionPane, as long as it's done in a way that plays nice with the Swing event thread.</p> <hr> <p><strong>Edit</strong><br> Your comment:</p> <blockquote> <ul> <li>The GUI will have three buttons that will represent sorting methods o Bubble o Quick o Merge</li> <li>The GUI will have an area for the user to input 5 numbers to sort. store them in an array or arrayList </li> <li>The GUI will have an area where each step of the sorting is displayed. This can be one area where each time a step is completed it replaces the line or several lines showing each step.</li> </ul> </blockquote> <p>You know that you can give your GUI 5 JTextAreas, one for each number to be entered.</p> <hr> <p><strong>Edit 2</strong><br> You state:</p> <blockquote> <p>So I am also trying something new. Not sure if it is right. So when button is pushed I put within the action listener: userInput = inputArea.getText(); Scanner input = new Scanner(userInput); Is this what you were talking about?</p> </blockquote> <p>That could work, but if you do it that way, you'll need a single JTextArea, and the user will have to know that their numbers should be separated by a single space. Again a Scanner can work well here since you can call <code>nextInt()</code> on it and get your data (as long as the data is numeric, and the correct number of numbers entered). But again, don't use a Scanner with System.in with a GUI except in some unusual circumstances. Also remember to close your Scanner when you're done with it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload