cerrar ventana secundaria
Publicado por Flavia (2 intervenciones) el 25/01/2007 15:26:03
Hola, me estoy iniciando en java asi que perdonen mi ignorancia. Tengo el siguiente problema: con un botón abro un Frame nuevo, que contiene un botón para salir y no puedo lograr que ese botón funcione, tengo el siguiente código:
public void actionPerformed(ActionEvent e)
{
if ("nombre_ActionCommand1".equals(e.getActionCommand())) {
ImageIcon img = new ImageIcon("C://Mis documentos/Mis imágenes/mapaentrerios-rutasyaccesos.gif");
JLabel imagen = new JLabel(img);
TextArea areaTexto;
JRadioButton boton1;
MenuBar barraMenu;
Menu menu1;
MenuItem opcionMenu1_1;
Panel panel1;
Frame f = new Frame();
f.setLayout(new BorderLayout());
panel1 = new Panel();
boton1 = new JRadioButton("Salir");
areaTexto = new TextArea(15, 10);
areaTexto.setEditable(false);
panel1.add(boton1);
f.add("North", panel1);
f.add("South", imagen);
f.setSize(500,500);
f.setVisible(true);
******* //lo que sigue es lo que no funciona y es una de las tantas maneras que he intentado. Si hago el actionPerformed aquí dentro o afuera me da error de duplicación del actionPerformed y del ActionEvent. Qué hago? Gracias!/***********
boton1.setActionCommand ("Salir");
boton1.addActionListener(this);
if ("Salir".equals(boton1.getActionCommand()))
{
f.setVisible(false);
}
}
else if ("nombre_ActionCommand2".equals(e.getActionCommand())) {
......
public void actionPerformed(ActionEvent e)
{
if ("nombre_ActionCommand1".equals(e.getActionCommand())) {
ImageIcon img = new ImageIcon("C://Mis documentos/Mis imágenes/mapaentrerios-rutasyaccesos.gif");
JLabel imagen = new JLabel(img);
TextArea areaTexto;
JRadioButton boton1;
MenuBar barraMenu;
Menu menu1;
MenuItem opcionMenu1_1;
Panel panel1;
Frame f = new Frame();
f.setLayout(new BorderLayout());
panel1 = new Panel();
boton1 = new JRadioButton("Salir");
areaTexto = new TextArea(15, 10);
areaTexto.setEditable(false);
panel1.add(boton1);
f.add("North", panel1);
f.add("South", imagen);
f.setSize(500,500);
f.setVisible(true);
******* //lo que sigue es lo que no funciona y es una de las tantas maneras que he intentado. Si hago el actionPerformed aquí dentro o afuera me da error de duplicación del actionPerformed y del ActionEvent. Qué hago? Gracias!/***********
boton1.setActionCommand ("Salir");
boton1.addActionListener(this);
if ("Salir".equals(boton1.getActionCommand()))
{
f.setVisible(false);
}
}
else if ("nombre_ActionCommand2".equals(e.getActionCommand())) {
......
Valora esta pregunta


0