Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import javax.swing.JCheckBox;
- import javax.swing.JFrame;
- public class Difficulty extends JFrame {
- /**
- *
- */
- private static JCheckBox easy;
- private static JCheckBox hard;
- private static Container pane;
- private Handeler handeler;
- private static final long serialVersionUID = 1L;
- public Difficulty() {
- super("Select a Difficulty");
- pane = new Container();
- getContentPane().add(pane);
- pane.add(Easy());
- pane.add(Hard());
- }
- public Component Hard() {
- handeler = new Handeler();
- hard = new JCheckBox("Hard");
- hard.setBounds(60, 40, 60, 50);
- hard.setVisible(true);
- hard.addItemListener(handeler);
- return hard;
- }
- private Component Easy() {
- handeler = new Handeler();
- easy = new JCheckBox("Easy");
- easy.setBounds(60, 0, 60, 50);
- easy.setVisible(true);
- easy.addItemListener(handeler);
- return easy;
- }
- public static void main(String[] args) {
- Difficulty gui = new Difficulty();
- gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- gui.setLocationRelativeTo(null);
- gui.setSize(200, 200);
- gui.setVisible(true);
- gui.setResizable(false);
- }
- private class Handeler implements ItemListener {
- @Override
- public void itemStateChanged(ItemEvent item) {
- if(item.getSource() == easy){
- for(int x = 0; x < 1; x++){
- if(hard.isSelected()){
- hard.setSelected(false);
- easy.setSelected(true);
- }else {easy.setSelected(true);}
- }
- }else if(item.getSource() == hard){
- for(int x = 0; x < 1; x++){
- if(easy.isSelected()){
- easy.setSelected(false);
- hard.setSelected(true);
- }else{hard.setSelected(true);}
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement