Hey there! Sign in to join this conversationNew here? Join for free

How do I put a value for the JRadio buttons and how can I make the buttons work? Watch

Announcements
    • Thread Starter
    Offline

    0
    ReputationRep:
    I am trying to make the "Exit", "cancel" and "pay" buttons work but I don't know if I should use if statement or actionlistener?

    and I am trying to put a value for the Radio buttons so it can be shown in the text area but nothing seems to work. I just need something simple not too complicated.

    public class RisitCoursework extends JFrame implements ActionListener,
    KeyListener {
    JButton cancel = new JButton("Cancel";);
    JButton exit = new JButton("Exit";);
    JButton pay = new JButton("Pay";);
    TextArea output = new TextArea(10, 40);
    JLabel title = new JLabel("Please select the type of ticket you
    wish to purchase";);
    JLabel coins = new JLabel(" Only Accpted:10p, 20p, 50p, £1.00 and
    £2.00 coins only";);
    JLabel notes = new JLabel(" £5.00, £10.00 and £20.00 notes only";);

    JFrame frame = new JFrame();
    frame.setTitle("Redwich Tram";);
    frame.setSize(355,350);
    frame.setLocationRelativeTo(null );
    frame.setDefaultCloseOperation(J Frame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel();

    JRadioButton single = new JRadioButton();
    single.setText("Single";);
    JRadioButton twoway = new JRadioButton();
    twoway.setText("Return";);
    JRadioButton zoneA = new JRadioButton();
    zoneA.setText("Zone A";);
    JRadioButton zoneA_B = new JRadioButton();
    zoneA_B.setText("Zone A&B";);



    ButtonGroup group = new ButtonGroup();
    group.add(single);
    group.add(twoway);
    group.add(zoneA);
    group.add(zoneA_B);

    panel.add(title);

    panel.add(single);
    panel.add(twoway);
    panel.add(zoneA);
    panel.add(zoneA_B);

    panel.add(coins);
    panel.add(notes);

    panel.add(output);
    panel.add(exit);
    panel.add(cancel);
    panel.add(pay);

    frame.getContentPane().add(panel );
    frame.setVisible(true);
    frame.setResizable(false);
    }
    Attached Images
     
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Should Spain allow Catalonia to declare independence?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.