Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

Answer To enhance the existing program Ill modify it to include additional mathematical operations such as subtraction multiplication and division Ill ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java How To Program Late Objects Version

Authors: Paul Deitel, Deitel & Associates

8th Edition

0136123716, 9780136123712

More Books

Students also viewed these Programming questions