Ayuda con un posible error que no detecto.
Publicado por System.out.println("Me llamo Carlos") (43 intervenciones) el 28/05/2020 17:45:38
Hola, he echo un programa para generar colores de fondo, el problema es que no mo lo hace bien donde esta el error, ayuden.
/
/
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
package color;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
public class RandomColor extends JPanel implements ActionListener {
private int randomColor;
@Override
public void actionPerformed(ActionEvent e) {
if (randomColor == 0) {
super.setBackground(Color.GREEN);
} else if (randomColor == 1) {
super.setBackground(Color.BLACK);
} else if (randomColor == 2) {
super.setBackground(Color.blue);
} else if (randomColor == 3) {
super.setBackground(Color.yellow);
}
}
public void setRandomColor() {
this.randomColor = (int) Math.random() * 3;
}
}
/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package color;
import javax.swing.JButton;
import javax.swing.JPanel;
public class LaminaColor extends JPanel {
JButton boton = new JButton("Random");
public LaminaColor() {
add(boton);
RandomColor rnd = new RandomColor ();
boton.addActionListener(rnd);
}
}
/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package color;
import javax.swing.JOptionPane;
public class UsoColor {
public static void main(String[] args) {
RandomColor r = new RandomColor();
r.setRandomColor();
FrameColor fr = new FrameColor();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package color;
import javax.swing.JFrame;
public class FrameColor extends JFrame {
public FrameColor() {
super.setLocationRelativeTo(null);
super.setExtendedState(MAXIMIZED_BOTH);
super.setDefaultCloseOperation(EXIT_ON_CLOSE);
LaminaColor m = new LaminaColor ();
add(m);
super.setVisible(true);
}
}
Valora esta pregunta


0