I have been programming for a short time and I am learning. My doubt is that I want to create a component (Bean) in netbeans that when I insert it in a Frame the button that I insert, I change the color of the button every time I press it.
I've done this but I do not know if I'm on the right track because when I insert the component (the button) into a jframe, it does not do anything.
import java.beans.*;
import java.io.Serializable;
import javax.swing.JButton;
public class LblBotonColores extends JButton implements Serializable {
private boolean cambioColor;
public boolean getCambioColor() {
return cambioColor;
}
public void setCambioColor(boolean cambioColor) {
this.cambioColor = cambioColor;
}
public LblBotonColores() {
JButton miBoton = new JButton("Hola Mundo");
if(getCambioColor()){
miBoton.setBackground(Color.RED);
}else{
miBoton.setBackground(Color.BLUE);
}
}
}
Thank you very much.