Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.GridLayout;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import javax.swing.JButton;
  7. import javax.swing.JFrame;
  8. import javax.swing.JPanel;
  9. import javax.swing.JRadioButton;
  10.  
  11. public class testje3 extends JFrame {
  12.  
  13.     public class GooiHandler implements ActionListener {
  14.         @Override
  15.         public void actionPerformed(ActionEvent e) {
  16.             int will = 1 + (int) (Math.random() * 6);
  17.             if (radBlauw.isSelected() == true) {
  18.                 for (int i = 0; i < will; i++) {
  19.                     btn[i].setBackground(Color.BLUE);
  20.                 }
  21.                 for (int i = 0; i < btn.length; i++) {
  22.                     btn[i].setBackground(Color.LIGHT_GRAY);
  23.                 }
  24.             } else {
  25.                 for (int i = 0; i < will; i++) {
  26.                     btn[i].setBackground(Color.RED);
  27.                 }
  28.                 for (int i = 0; i < btn.length; i++) {
  29.                     btn[i].setBackground(Color.LIGHT_GRAY);
  30.                 }
  31.             }
  32.         }
  33.     }
  34.  
  35.     JRadioButton radBlauw = new JRadioButton("Blauw");
  36.     JRadioButton radRood = new JRadioButton("Rood");
  37.     JButton btn[] = new JButton[6];
  38.     JButton btnGooi = new JButton("Gooi");
  39.  
  40.     public testje3() {
  41.         super("Dobbelsteen");
  42.  
  43.         JPanel inhoudsPaneel = new JPanel(new BorderLayout());
  44.         JPanel links = new JPanel(new GridLayout(1, 1));
  45.         JPanel rechts = new JPanel(new GridLayout(3, 3));
  46.  
  47.         for (int i = 0; i < 6; i++) {
  48.             btn[i] = new JButton();
  49.             rechts.add(btn[i]);
  50.         }
  51.         inhoudsPaneel.setOpaque(true);
  52.  
  53.         links.add(btnGooi);
  54.         rechts.add(radBlauw);
  55.         rechts.add(radRood);
  56.  
  57.         inhoudsPaneel.add(links, BorderLayout.WEST);
  58.         inhoudsPaneel.add(rechts, BorderLayout.EAST);
  59.  
  60.         btnGooi.addActionListener(new GooiHandler());
  61.  
  62.         add(inhoudsPaneel);
  63.  
  64.         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  65.         setSize(400, 200);
  66.         setLocation(500, 500);
  67.         setVisible(true);
  68.  
  69.     }
  70.  
  71.     public static void main(String[] args) {
  72.         new testje3();
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement