Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Can't get getText in jTextArea to work properly
    primarykey
    data
    text
    <p>I have a seperate JFrame where there is a text box (jTextArea) that takes numbers as inputs, each separated with a new line. Upon closing the JFrame with the text box, the data is supposed to be stored in an ArrayList of integers. The ArrayList is checked when clicking a button in the main JFrame and errors are logged if they happen.</p> <p>The code for the JFrame with the jTextArea looks like this:</p> <pre><code>private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { boolean success = false; try{ selectedTime = Long.parseLong(jTextField1.getText()); if(selectedTime &gt;= 10000){ success = true; if(!jTextArea1.equals("") &amp;&amp; !jTextArea1.equals(null)){ try{ for(int i = 0; i &lt; jTextArea1.getLineCount(); i++){ n = Integer.parseInt(jTextArea1.getText(jTextArea1.getLineStartOffset(i),jTextArea1.getLineEndOffset(i))); if(n &lt;= 172){ worldsChosen.add(n); } } }catch(Exception e){ errorsHappened = true; } } }else{ javax.swing.JOptionPane.showMessageDialog(null,"The specified time was not above or equal to 10000 ms. Please try again."); success = false; } }catch(Exception e){ javax.swing.JOptionPane.showMessageDialog(null,"The specified time was not set in numbers exclusively. Please try again."); success = false; } if(success){ gui.hideWorlds(); } } </code></pre> <p>Note: it also checks whether a text box has a number input equal to or above 10000 (this works).</p> <p>The code for the main JFrame:</p> <pre><code> if(jCheckBox5.isSelected()){ checkWorld = true; if(!worldsChosen.isEmpty()){ changeWorlds = true; }else{ log("You've selected the option for automatic world switching,"); log("but all of your inputs weren't formatted correctly."); errorsHappened = true; } }else{ errorsHappened = false; } if(errorsHappened == true){ log("One or multiple worlds weren't added due to incorrect formatting."); log("Retry to make script automatically change worlds."); } </code></pre> <p>Whenever I run the script with the check box selected and something formatted correctly in the text area (like this):</p> <pre><code>1 2 3 4 5 </code></pre> <p>etc.</p> <p>It outputs all of the log messages (as if the check box had been selected but none of the inputs were formatted correctly).</p> <p>I've tried to the best of my knowledge to fix this, but I just can't see how it messes up.</p> <p>Any help appreciated :).</p> <p>Mike Haye.</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. 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