fork download
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.util.*;
  4.  
  5. public class TicketPrice extends Frame implements ActionListener {
  6. Label price = new Label();
  7.  
  8.  
  9. String[] cf1 = {
  10. "子供",
  11. "学生",
  12. "一般"
  13. };
  14.  
  15. String[] cf2 = {
  16. "一般",
  17. "3D",
  18. "映画の日"
  19. };
  20.  
  21. Map<String, Map<String, Integer>> priceMap = new HashMap<String, Map<String, Integer>>() {
  22. {
  23. put(cf1[0], new HashMap<String, Integer>() {
  24. {
  25. put(cf2[0], 1000);
  26. put(cf2[1], 1400);
  27. put(cf2[2], 1000);
  28. }
  29. });
  30. put(cf1[1], new HashMap<String, Integer>() {
  31. {
  32. put(cf2[0], 1500);
  33. put(cf2[1], 1900);
  34. put(cf2[2], 1100);
  35. }
  36. });
  37. put(cf1[2], new HashMap<String, Integer>() {
  38. {
  39. put(cf2[0], 1800);
  40. put(cf2[1], 2200);
  41. put(cf2[2], 1100);
  42. }
  43. });
  44. }
  45. };
  46.  
  47. public void actionPerformed(ActionEvent e) {
  48. String cbl = cbg.getSelectedCheckbox().getLabel();
  49. String bl = ((Button) e.getSource()).getLabel();
  50. price.setText(priceMap.get(cbl).get(bl) + "円");
  51. }
  52.  
  53. public TicketPrice() {
  54. super("映画料金");
  55.  
  56. setSize(400, 150);
  57. setLayout(new GridLayout(3, 3));
  58.  
  59. for (int i = 0; i < cf1.length; i++)
  60. add(new Checkbox(cf1[i], cbg, i == 0));
  61.  
  62. for (int i = 0; i < cf2.length; i++) {
  63. Button b = new Button(cf2[i]);
  64. b.addActionListener(this);
  65. add(b);
  66. }
  67.  
  68. add(new Label("料金"));
  69. add(price);
  70.  
  71. addWindowListener(new WindowAdapter() {
  72. public void windowClosing(WindowEvent e) {
  73. System.exit(0);
  74. }
  75. });
  76.  
  77. setVisible(true);
  78. }
  79.  
  80. public static void main(String[] args) {
  81. new TicketPrice();
  82. }
  83. }
Runtime error #stdin #stdout #stderr 0.23s 35204KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
	at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
	at java.awt.Window.<init>(Window.java:536)
	at java.awt.Frame.<init>(Frame.java:420)
	at TicketPrice.<init>(Main.java:55)
	at TicketPrice.main(Main.java:82)