Botones
Publicado por juan pablo (3 intervenciones) el 06/01/2017 00:04:47
Disculpen tengo una pregunta es que tengo programa que con un bucle de botones pero solo me lee la accion de uno no ellos como puedo hacer para que lea todos los botones a la vez
espero que me puedan ayudar gracias :)
espero que me puedan ayudar gracias :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.*;
public class Matriz extends JFrame implements ActionListener {
JButton b1;
Random colores1 = new Random();
Random colores2 = new Random();
Random colores3 = new Random();
public Matriz() {
setTitle(" ");
setSize(400, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(5, 5));
for (int i = 0; i < 25; i++) {
b1 = new JButton("Hola Mundo");
add(b1);
}
b1.addActionListener(this);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(b1)) {
b1.setBackground(new Color(colores1.nextInt(200), colores2.nextInt(255), colores3.nextInt(255)));
}
}
}
Valora esta pregunta
0