Link to home
Start Free TrialLog in
Avatar of LaleaN
LaleaN

asked on

Java Applet

Hi all,

I need to know how to close an applet window that is running off an applet.   It is called from the applet.  I have tried the following from a class called

class VehicleMaintenance extends Applet
   implements ActionListener {
...........

if (source == button1 ) {
          Frame f = new Frame("Rent-Ur-Wheels");
          VehicleRental vR = new VehicleRental();
          f.add(vR);
          f.setSize(300, 100);
          f.show();
          WindowListener l =
                    new WindowAdapter() {
                             public void windowClosing(WindowEvent e) {
                         System.exit(0);
                  }
               };
        f.addWindowListener(l);
}

...........
}
but that does not seem to close the window down at all.  It displays the window and its contents of the VehicleRental Class - class VehicleRental extends Panel{...} , minimises and maximises but wont close.

Can someone help please
Thanks.
Avatar of Ovi
Ovi

if (source == button1 ) {
          final Frame f = new Frame("Rent-Ur-Wheels");
          VehicleRental vR = new VehicleRental();
          f.add(vR);
          f.setSize(300, 100);
          f.show();
          WindowListener l =
                   new WindowAdapter() {
                             public void windowClosing(WindowEvent e) {
                 f.setVisible(false);
                 f.dispose();
                       //  System.exit(0);
                  }
               };
        f.addWindowListener(l);
}

Ovi, that is an answer, not a comment.

sey.
Avatar of LaleaN

ASKER

ovi - ty but it did not work - the compiler gives me errors to say
Attempt to use a non-final variable f from a different method.From enclosing blocks only final local varibles are available
Avatar of LaleaN

ASKER

ovi - ty but it did not work - the compiler gives me errors to say
Attempt to use a non-final variable f from a different method.From enclosing blocks only final local varibles are available
ASKER CERTIFIED SOLUTION
Avatar of Ovi
Ovi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LaleaN

ASKER

Ovi,

Ty - i missed it and i even checked but there you go.  Thank you again.

Lalea.