public class SwitchErrorsGui
1: public class SwitchErrorsGui
2: {
3: public static void main(String[] args)
4: {
5: String input;
6:
7: JOptionPane.showMessageDialog(
8: null, "Key: 1=blue, 2=red, 3=green");
9:
10: input = JOptionPane.showInputDialog(
11: "Enter a number and I'll return the corresponding color");
12: int number = Integer.parseInt(input)
13:
14: switch(number)
15: {
16: case 1:
17: JOptionPane.showMessageDialog(
18: null, "You choose red!");
19: break;
20: case 2:
21: JOptionPane.showMessageDialog(
22: null, "You choose blue!");
23: break;
24: case 3:
25: JOptionPane.showMessageDialog(
26: null, "You choose green!");
27: default:
28: JOptionPane.showMessageDialog(
29: null, "Color not available!");
30: break;
31: }
32: System.exit(0);
33: }
34: }