The simpliest way: Create your own dialog, don't use JOption.
Use JFormattedTextfield for input to make sure the input text is a number.
Your dialog needs 3 private int variables int num1;
int num2;
int num3;
Your dialog should also offer 3 public or protected methods: int getNumber1() {
return num1;
}
int getNumber2() {
return num2;
}
int getNumber3() {
return num1;
}
On the close window event store the content of the 3 input fields to 3 int variables.
Thats's pretty much it.
If there is a OK or a CANCEL button you must write a logic for them, too. You can for example use a enmum for all avaiable buttons. Then you must offer a method which returns the pressed button after the dialog is closed.
public static enum Buttons{OK, CANCEL};
private Buttons pressedButton = Buttons.CANCEL;
public Buttons getPresedButton() {
return pressedButton;
}
Access the dialog like this: Mydialog diag = new MyDialog();
diag.setVisible(true);
if (diag.getPressedButton() == MyDialog.Buttons.OK) {
System.out.println("1st number: " + diag.getNumber1());
System.out.println("2nd number: " + diag.getNumber2());
System.out.println("3rd number: " + diag.getNumber3());
} else {
System.out.println("Aborted");
}
I don't have too much experience with the JOptionpane, maybe you can extend a JOptionPane, so you don't have to implement the button-handlig yourself.