Solved

Java Applet

Posted on 2002-05-20
6
954 Views
Last Modified: 2013-11-23
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.
0
Comment
Question by:LaleaN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Ovi
ID: 7023237
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);
}

0
 
LVL 1

Expert Comment

by:sey7
ID: 7023435
Ovi, that is an answer, not a comment.

sey.
0
 

Author Comment

by:LaleaN
ID: 7023500
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:LaleaN
ID: 7023527
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
0
 
LVL 9

Accepted Solution

by:
Ovi earned 50 total points
ID: 7023827
In my original post was like this :
final Frame f = new Frame("Rent-Ur-Wheels");

this meens the f variable is final and you will not get any errors.


Hi sey7 !
0
 

Author Comment

by:LaleaN
ID: 7023847
Ovi,

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

Lalea.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question