
24/11/2011, 08:13
|
 | | | Fecha de Ingreso: junio-2011
Mensajes: 85
Antigüedad: 13 años, 8 meses Puntos: 19 | |
Respuesta: e.getSource? la variable "JButton boton1" la estas declarando como local en el constructor, tenes que declararla fuera del constructor.
El codigo seria así:
public class Boton extends JFrame implements ActionListener {
//las declaras en la clase y no dentro del constructor private JButton boton1;
private JButton boton2;
public Boton(){
super("MI VENTANA");
setSize(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
boton1 = new JButton("ACEPTAR");
boton2 = new JButton("CANCELAR");
FlowLayout s = new FlowLayout();
setLayout(s);
add(boton1);
add(boton2);
setVisible(true);
boton1.addActionListener(this);
boton2.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==boton1)
System.exit(0); |