Created
January 6, 2024 06:38
-
-
Save L8RFN/c91a85739eb8359e63a233002d03ebaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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