Skip to content

Instantly share code, notes, and snippets.

@L8RFN
Created January 6, 2024 06:38
Show Gist options
  • Save L8RFN/c91a85739eb8359e63a233002d03ebaa to your computer and use it in GitHub Desktop.
Save L8RFN/c91a85739eb8359e63a233002d03ebaa to your computer and use it in GitHub Desktop.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GUI extends JFrame {
JPanel left = new JPanel(new GridLayout(3,2,5,5));
JPanel right = new JPanel(new GridLayout(8,1));
JRadioButton boxes [] = new JRadioButton[6];
String country [] = {"Jordan", "Palestine", "Egypt", "Algeria", "Saudi Arabia", "Mauritania" };
JButton clear = new JButton("Clear");
String tickets [] = {"one ticket", "two ticket", "three tickets"};
JComboBox comTickets = new JComboBox(tickets);
ButtonGroup group = new ButtonGroup(); // important,, buttongroup
public GUI() throws HeadlessException {
for (int i = 0; i < boxes.length; i++) {
boxes[i] = new JRadioButton(country[i]);
left.add(boxes[i]);
group.add(boxes[i]);
}
right.add(comTickets,BorderLayout.NORTH);
clear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
group.clearSelection();
}
});
add(clear,BorderLayout.SOUTH);
add(left,BorderLayout.WEST);
add(right);
setTitle("Tickets");
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(500,300);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment