fork download
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. public class TicketPrice extends JFrame {
  5.  
  6. public static void main(String[] args) {
  7. TicketPrice ticketPrice = new TicketPrice("映画料金");
  8. ticketPrice.setVisible(true);
  9. }
  10.  
  11. TicketPrice(String title) {
  12. setTitle(title);
  13. setSize(400, 150);
  14. setLocationRelativeTo(null);
  15. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.  
  17. JPanel panel = new JPanel();
  18. GridLayout layout = new GridLayout(3, 3);
  19. panel.setLayout(layout);
  20.  
  21. JRadioButton childRadioButton = new JRadioButton("子供");
  22. JRadioButton studentRadioButton = new JRadioButton("学生");
  23. JRadioButton adultRadioButton = new JRadioButton("大人");
  24.  
  25. ButtonGroup group = new ButtonGroup();
  26. group.add(childRadioButton);
  27. group.add(studentRadioButton);
  28. group.add(adultRadioButton);
  29.  
  30. panel.add(childRadioButton);
  31. panel.add(studentRadioButton);
  32. panel.add(adultRadioButton);
  33.  
  34. JButton general = new JButton("一般");
  35. JButton threeDimensional = new JButton("3D");
  36. JButton movieDay = new JButton("映画の日");
  37.  
  38. panel.add(general);
  39. panel.add(threeDimensional);
  40. panel.add(movieDay);
  41.  
  42. JLabel fee = new JLabel("料金", JLabel.CENTER);
  43. JLabel result = new JLabel();
  44. result.setOpaque(true);
  45. result.setBackground(Color.WHITE);
  46. result.setHorizontalAlignment(JLabel.CENTER);
  47.  
  48. panel.add(fee);
  49. panel.add(result);
  50.  
  51. general.addActionListener(event -> {
  52. if (childRadioButton.isSelected()) {
  53. result.setText("1000円");
  54. } else if (studentRadioButton.isSelected()) {
  55. result.setText("1500円");
  56. } else if (adultRadioButton.isSelected()) {
  57. result.setText("1800円");
  58. }
  59. });
  60.  
  61. threeDimensional.addActionListener(event -> {
  62. if (childRadioButton.isSelected()) {
  63. result.setText("1400円");
  64. } else if (studentRadioButton.isSelected()) {
  65. result.setText("1900円");
  66. } else if (adultRadioButton.isSelected()) {
  67. result.setText("2200円");
  68. }
  69. });
  70.  
  71. movieDay.addActionListener(event -> {
  72. if (childRadioButton.isSelected()) {
  73. result.setText("1000円");
  74. } else if (studentRadioButton.isSelected() || adultRadioButton.isSelected()) {
  75. result.setText("1100円");
  76. }
  77. });
  78.  
  79. getContentPane().add(panel, BorderLayout.CENTER);
  80. }
  81.  
  82. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:4: error: class TicketPrice is public, should be declared in a file named TicketPrice.java
public class TicketPrice extends JFrame {
       ^
1 error
stdout
Standard output is empty