Código fuente del botón del mini programa
Importar evento de acción Java .
Importar evento de acción Java . .swing.jbutton;
Importar javax.swing.jframe;
Importar javax.swing.jpanel;
Pantalla de clase pública {
Public static void main(String args[]){
new Win();
}
La clase estática Win extiende JFrame para implementar ActionListener{ p >
JPanel jp = nuevo JPanel();
JButton JB[]= nuevo JButton[4];
Public Win(){
this .setBounds(0, 0, 320, 320);
Color c[] = {Color.rojo, Color.amarillo, color }; ( color . negro);
for(int I = 0;i<4;i++){
JB[I]= new JButton();
if (i!=3){
jb[i]. establecer fondo(c[I]);
}else {
Jb[i]. setText(" salir ");
}
jb[i]. addActionListener(this);
jp add(JB[I]);
}
this . >this . set visible(true);
}
acción de anulación pública realizada (evento de acción e){
Si (!((jbutton) e. getsource()).gettext().equals("exit")){//Si no es un botón de salida, cambie el color.
jp . establecer fondo((JButton)e. getsource()). obtener fondo());
}
Otros
system .exit(0); //Salir
}
}
}