Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - My JOptionPane does not close when cancel or 'x' is pressed
    primarykey
    data
    text
    <p>I have the following class (testDate) which tests another class (MyDate), when these 3 lines are executed, the inputDialog box doesn't close when I cancel or little 'x' top right.</p> <pre><code>myDay = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the day of the month, you're travelling on: ")); myMonth = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the month (1-12), you're travelling on: ")); myYear = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the year, you're travelling on: ")); </code></pre> <p>Here is the full testDate Class:</p> <pre><code>import javax.swing.JOptionPane; public class testDate { public static void main(String[] args){ int myDay = 0, myMonth = 0, myYear = 0; // initialising variables boolean dateCorrect = false; MyDate userTravelDate; do { try { do { myDay = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the day of the month, you're travelling on: ")); myMonth = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the month (1-12), you're travelling on: ")); myYear = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the year, you're travelling on: ")); userTravelDate = new MyDate(myDay, myMonth, myYear); } while (userTravelDate.isDateValid(userTravelDate.formDate()) == false); dateCorrect = true; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Please enter only integers!", "Error Occurred!", JOptionPane.ERROR_MESSAGE); } } while (dateCorrect == false); JOptionPane.showMessageDialog(null, myDay + "-" + myMonth + "-" + myYear); } </code></pre> <p>}</p> <p>I would like to know if the input dialog boxes can be closed if I press 'X' or cancel, because at the moment if either 'x' or cancel are pressed it executes the line:</p> <pre><code>JOptionPane.showMessageDialog(null, "Please enter only integers!", "Error Occurred!", JOptionPane.ERROR_MESSAGE); </code></pre> <p>and keeps looping asking for day, month and year until these are right.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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