Mickeys
asked on
How do I manage to make my first messagebox to stay up?
I was wondering how I manage to ask a question in a messagebox....and if the question is wrong a nother messagebox opens. When I click ok on the second box I want to comeback to the first one. Right now everything just ends.
See code
See code
int response = JOptionPane.showOptionDialog(
null,
connectionPanel,
ConnectTitle,
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
ConnectOptionNames,
ConnectOptionNames[0]);
swithc(.... bla bla)
case: 1 login();
public void login(){
JOptionPane.showMessageDialog(this, "name does not exist");
}
Set it in a loop that only exits when the answer is correct
while (response!= desiredResponse)
{
int response = JOptionPane.showOptionDial og(
null,
connectionPanel,
ConnectTitle,
JOptionPane.OK_CANCEL_OPTI ON,
JOptionPane.INFORMATION_ME SSAGE,
null,
ConnectOptionNames,
ConnectOptionNames[0]);
swithc(.... bla bla)
case: 1 login();
{
int response = JOptionPane.showOptionDial
null,
connectionPanel,
ConnectTitle,
JOptionPane.OK_CANCEL_OPTI
JOptionPane.INFORMATION_ME
null,
ConnectOptionNames,
ConnectOptionNames[0]);
swithc(.... bla bla)
case: 1 login();
should be:
int response = -1;
while (response!= desiredResponse)
{
response = JOptionPane.showOptionDial og(
give me a yell if you don't understand
int response = -1;
while (response!= desiredResponse)
{
response = JOptionPane.showOptionDial
give me a yell if you don't understand
I actually have a full example from one of my students but can't find it right now.
ASKER
Where?
// Connect or quit
int response = JOptionPane.showOptionDialog(
null,
connectionPanel,
ConnectTitle,
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
ConnectOptionNames,
ConnectOptionNames[0]);
switch (response) {
case 0:
System.out.println("0");
break;
case 1:
login();
break;
case 2:
case -1:
//... Both the quit button (3) and the close box(-1) handled here.
System.exit(0); // It would be better to exit loop, but...
default:
//... If we get here, something is wrong. Defensive programming.
JOptionPane.showMessageDialog(null, "Unexpected response " + response);
}
}
public void login()
{
JOptionPane.showMessageDialog(this, "No name");
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Set it before your switch
int response = Integer.MIN_VALUE;
while (response < 0 && response > 2) {
...
}
while (response < 0 && response > 2) {
...
}
Glad i could help