Aquí os paso el código:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class AppletVentana extends Applet implements ActionListener{
Button b;
public void init(){
b=new Button("Abrir ventana");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e){
VentanaCucu vc=new VentanaCucu("Mi Ventana");
vc.setSize(300,300);
vc.setBackground(Color.yellow);
vc.show();
}
}
class VentanaCucu extends Frame{
VentanaCucu(String titulo){
super(titulo);
addWindowListener(new CerrarVentanaCucu());
}
}
class CerrarVentanaCucu extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
Hola:
No puedes llamar a System.exit() desde un applet debido a las
restricciones que estos tienen a la hora de acceder al sistema. Lo que
deberías hacer es algo así...
public void windowClosing(WindowEvent e) {
e.getWindow().setVisible(false);
}
Saludos!
[tomby]
>> class CerrarVentanaCucu extends WindowAdapter{
>> public void windowClosing(WindowEvent e){
>> System.exit(0);
>> }
>> }
> No puedes llamar a System.exit() desde un applet debido a las
> restricciones que estos tienen a la hora de acceder al sistema. Lo que
> deberías hacer es algo así...
> public void windowClosing(WindowEvent e) {
> e.getWindow().setVisible(false);
> }
Con eso la esconde no la cierra, lo que puede ser un problema...
El método es dispose():
--8<-------------------------------------------------
dispose
public void dispose()Releases all of the native screen resources used by
this Window, its subcomponents, and all of its owned children. That is, the
resources for these Components will be destroyed, any memory they consume
will be returned to the OS, and they will be marked as undisplayable.
[...]
--8<-------------------------------------------
--
Juan Gonzalo de Silva Medina
if(!Linux) throw new Exception(" :( ");