import javax.swing.JOptionPane; public class GUI_DropDownList { public static void main(String[] args) { int answer=0; int x=JOptionPane.showConfirmDialog(null,Do you
Question:
import javax.swing.JOptionPane;
public class GUI_DropDownList {
public static void main(String[] args) {
int answer=0;
int x=JOptionPane.showConfirmDialog(null,"Do you want to continue...", "OPTION", JOptionPane.YES_NO_OPTION);
if (x==0) {
answer=dialogAskingTheUserToSelectAString();
if (answer != 0)
JOptionPane.showMessageDialog(null, "Message " + answer);
else
JOptionPane.showMessageDialog(null, "You have cancelled the operation", "ALERT",JOptionPane.ERROR_MESSAGE);
}
else
JOptionPane.showMessageDialog(null, "Bye...", "ALERT",JOptionPane.ERROR_MESSAGE);
}
static int dialogAskingTheUserToSelectAString() {
Object[] possibleValues = {"Message 1","Message 2","Message 3","Message 4"};
Object selectedValue = JOptionPane.showInputDialog(null,"Choose one", "Input",JOptionPane.INFORMATION_MESSAGE, null,possibleValues, possibleValues[0]);
int result=0;
if (selectedValue=="Message 1")
result = 1;
else if (selectedValue=="Message 2")
result = 2;
else if (selectedValue=="Message 3")
result = 3;
else if (selectedValue=="Message 4")
result = 4;
return result;
}
}
Try to encode the program above and observe the result.
After you have successfully run the program, modify it, and add more operations to perform such as the following mathematical operation.
Subtraction
Multiplication
Division (It should have division by zero error if in case a number is divided by zero).
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates