Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6099881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:19:25+00:00 2026-05-23T13:19:25+00:00

I have a seperate JFrame where there is a text box (jTextArea) that takes

  • 0

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.

The code for the JFrame with the jTextArea looks like this:

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        boolean success = false;
        try{
            selectedTime = Long.parseLong(jTextField1.getText());
            if(selectedTime >= 10000){
                success = true;
                if(!jTextArea1.equals("") && !jTextArea1.equals(null)){
                    try{
                        for(int i = 0; i < jTextArea1.getLineCount(); i++){
                            n = Integer.parseInt(jTextArea1.getText(jTextArea1.getLineStartOffset(i),jTextArea1.getLineEndOffset(i)));
                            if(n <= 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();
        }
    }

Note: it also checks whether a text box has a number input equal to or above 10000 (this works).

The code for the main JFrame:

 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.");               
            }

Whenever I run the script with the check box selected and something formatted correctly in the text area
(like this):

1
2
3
4
5

etc.

It outputs all of the log messages (as if the check box had been selected but none of the inputs were formatted correctly).

I’ve tried to the best of my knowledge to fix this, but I just can’t see how it messes up.

Any help appreciated :).

Mike Haye.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:19:26+00:00Added an answer on May 23, 2026 at 1:19 pm

    Read the api doc of getText(int, int): the second argument is not an offset. It’s a length.

    Side note 1: it should probably be easier to get all the text as a single string and split on newline chars, and the parse every string into an integer.

    Side note 2: The test if (jTextArea1.equals("")) can’t succeed. A JTextArea instance will never be equals to a String instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java game i'm creating and each window is a seperate JFrame
Suppose you have two seperate ASP.NET Web Application projects that both need to use
Say If i have two classes, in each class is a different JFrame, e.g
I have a new web app that is packaged as a WAR as part
I have seperate functions for reading from a text file (depending on whether its
I am currently have two seperate applications, both perform seperate tasks, but there is
I want to have a seperate project that runs my server communication code in
I have a method running in a seperate thread. The thread is created and
i have a log file which contains hundreds/thousands of seperate XML messages and need
I am trying to have a table header, in a seperate div stay in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.