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) {

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).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer To enhance the existing program Ill modify it to include additional mathematical operations such as subtraction multiplication and division Ill ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!