Advertisement
Guest User

Untitled

a guest
Aug 30th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. import java.awt.Component;
  2. import java.awt.Container;
  3. import java.awt.event.ItemEvent;
  4. import java.awt.event.ItemListener;
  5.  
  6. import javax.swing.JCheckBox;
  7. import javax.swing.JFrame;
  8.  
  9.  
  10. public class Difficulty extends JFrame {
  11.  
  12. /**
  13. *
  14. */
  15. private static JCheckBox easy;
  16. private static JCheckBox hard;
  17. private static Container pane;
  18. private Handeler handeler;
  19. private static final long serialVersionUID = 1L;
  20.  
  21. public Difficulty() {
  22. super("Select a Difficulty");
  23. pane = new Container();
  24. getContentPane().add(pane);
  25. pane.add(Easy());
  26. pane.add(Hard());
  27. }
  28.  
  29. public Component Hard() {
  30. handeler = new Handeler();
  31. hard = new JCheckBox("Hard");
  32. hard.setBounds(60, 40, 60, 50);
  33. hard.setVisible(true);
  34. hard.addItemListener(handeler);
  35. return hard;
  36. }
  37.  
  38. private Component Easy() {
  39. handeler = new Handeler();
  40. easy = new JCheckBox("Easy");
  41. easy.setBounds(60, 0, 60, 50);
  42. easy.setVisible(true);
  43. easy.addItemListener(handeler);
  44. return easy;
  45. }
  46.  
  47. public static void main(String[] args) {
  48. Difficulty gui = new Difficulty();
  49. gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  50. gui.setLocationRelativeTo(null);
  51. gui.setSize(200, 200);
  52. gui.setVisible(true);
  53. gui.setResizable(false);
  54.  
  55. }
  56.  
  57. private class Handeler implements ItemListener {
  58.  
  59. @Override
  60. public void itemStateChanged(ItemEvent item) {
  61.  
  62. if(item.getSource() == easy){
  63. for(int x = 0; x < 1; x++){
  64. if(hard.isSelected()){
  65. hard.setSelected(false);
  66. easy.setSelected(true);
  67. }else {easy.setSelected(true);}
  68. }
  69.  
  70. }else if(item.getSource() == hard){
  71. for(int x = 0; x < 1; x++){
  72. if(easy.isSelected()){
  73. easy.setSelected(false);
  74. hard.setSelected(true);
  75. }else{hard.setSelected(true);}
  76. }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement