Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JRadioButton;
- public class testje3 extends JFrame {
- public class GooiHandler implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- int will = 1 + (int) (Math.random() * 6);
- if (radBlauw.isSelected() == true) {
- for (int i = 0; i < will; i++) {
- btn[i].setBackground(Color.BLUE);
- }
- for (int i = 0; i < btn.length; i++) {
- btn[i].setBackground(Color.LIGHT_GRAY);
- }
- } else {
- for (int i = 0; i < will; i++) {
- btn[i].setBackground(Color.RED);
- }
- for (int i = 0; i < btn.length; i++) {
- btn[i].setBackground(Color.LIGHT_GRAY);
- }
- }
- }
- }
- JRadioButton radBlauw = new JRadioButton("Blauw");
- JRadioButton radRood = new JRadioButton("Rood");
- JButton btn[] = new JButton[6];
- JButton btnGooi = new JButton("Gooi");
- public testje3() {
- super("Dobbelsteen");
- JPanel inhoudsPaneel = new JPanel(new BorderLayout());
- JPanel links = new JPanel(new GridLayout(1, 1));
- JPanel rechts = new JPanel(new GridLayout(3, 3));
- for (int i = 0; i < 6; i++) {
- btn[i] = new JButton();
- rechts.add(btn[i]);
- }
- inhoudsPaneel.setOpaque(true);
- links.add(btnGooi);
- rechts.add(radBlauw);
- rechts.add(radRood);
- inhoudsPaneel.add(links, BorderLayout.WEST);
- inhoudsPaneel.add(rechts, BorderLayout.EAST);
- btnGooi.addActionListener(new GooiHandler());
- add(inhoudsPaneel);
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- setSize(400, 200);
- setLocation(500, 500);
- setVisible(true);
- }
- public static void main(String[] args) {
- new testje3();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement