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

  • SEARCH
  • Home
  • 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 8364961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:33:09+00:00 2026-06-09T12:33:09+00:00

How would I go about adding a way for the loop to exit if

  • 0

How would I go about adding a way for the loop to exit if the user clicks cancel. If anyone is willing there is a commented out section of code and it is referenced in the Tourist Input Button section of code but it doesnt work. Thanks

 /////////Convert
     public static int[] convertIntegers(java.util.List<Integer> elemIntegers)
{
    int[] elements = new int[elemIntegers.size()];
    for (int i=0; i < elements.length; i++)
    {
        elements[i] = elemIntegers.get(i).intValue();
    }
    return elements;
}

The full source code is here: http://pastebin.com/r4tEeatu

The specific section is

insertTableF.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int wayPoint1 = 0;
            int wayPoint2 = 0;
            int PassTime = 0;
            Statement statementR;

            if (loggedIn == 1) {

                while (passedR == 0) {
                    try {
                        if (wayPoint1 == 0) {
                            sTagR = JOptionPane.showInputDialog("Please enter the Rhino Tag number:");
                            iTagR = Integer.parseInt(sTagR);
                            wayPoint1 = 1;
                        }
                        if (wayPoint2 == 0) {
                            sGPSX = JOptionPane.showInputDialog("Please enter the horizontal GPS Grid Numbers(eg.3123):");
                            iGPS = Integer.parseInt(sGPSX);

                            wayPoint2 = 1;
                        }

                        sGPSY = JOptionPane.showInputDialog("Please enter the vertical GPS Grid Letters(eg.XXYY:");
                        while (PassTime == 0) {
                            sTime = JOptionPane.showInputDialog("Please enter the Last date you saw the Rhino(YYYY-MM-DD):");
                            //      if (!sTime.equals("") || sTime !=null){
                            if (isValidDate(sTime)) {
                                PassTime = 1;
                            } else {
                                JOptionPane.showMessageDialog(null, "Please use the date format YYYY-MM-DD.");
                            }
                            //      } else {
                            //              JOptionPane.showMessageDialog(null, "Please use the date format YYYY-MM-DD.");
                            //      }
                        }
                        sLocation = JOptionPane.showInputDialog("Please enter the Last place you saw the Rhino:");

                        passedR = 1;
                    } catch (NumberFormatException nfe) {
                        passedR = 0;
                        JOptionPane.showMessageDialog(null, "Please use numbers for the Rhino Tag field.");
                    }
                }
                if (passedR == 1) {
                    ComboGPS = iGPS + " " + sGPSY;
                    try {
                        Connection insertTable = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=C:/Users/Jethro/Desktop/IT Project Files/dbRhino.mdb", "", "");
                        String sql = "insert into TblRhinoLoc values ( '" + iTagR + "', '" + ComboGPS + "', '" + sTime + "', '" + sLocation + "')";

                        try {
                            statementR = insertTable.createStatement();
                            statementR.executeUpdate(sql);

                            JOptionPane.showMessageDialog(null, "Data entered successfully!");
                            wayPoint1 = 0;
                            wayPoint2 = 0;
                        } catch (Exception err) {
                            System.out.println(err);
                            JOptionPane.showMessageDialog(null, err);
                        }
                        UpdateJTableRanger();
                    } catch (SQLException er) {
                        System.out.println("Error: " + er);
                    }

                } else {

                }
            } else {
                JOptionPane.showMessageDialog(null, "Please make sure you are logged in before editing sensitive data.");
            }
        }
    });
  • 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-06-09T12:33:10+00:00Added an answer on June 9, 2026 at 12:33 pm

    Exactly which loop do you want to break out of?

    I’m assuming you want to exit the while (passedR == 0) loop when the user cancels one of the JoptionPane.showInputDialog options.

    while (passedR == 0) {
    ...
                sTagR = JOptionPane.showInputDialog(...);
                if (sTagR == null) {
                     // User canceled.
                     break;
                } else {
                   ...
                }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I go about dynamically adding commas as a user is entering numbers?
How would I go about adding a comment section under each photo in this
How would I go about adding a dynamic .......... to a restaurant menu in
How would someone go about adding check boxes to only the children of a
I would like to know how one goes about adding functionality from one open
I'm wondering how i would go about making the following application: a user signs
How would I go about adding a simple 2 minute timer to my app
How would one go about adding an event handler to a control in a
how would I go about adding meta data to a json response in rails
I would like to use Google Analytics but I am concerned about adding more

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.