0

This code is for closing the appletviewer window when the "close" button is pressed. It works fine; although, after closing the appletviewer window an error is given.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
//withpannelSimpleApplet class
public class withpannelSimpleApplet extends JApplet {
    public void init() {
        JPanel p = new JPanel(new GridLayout(0,1,5,5));    
        JButton close = new JButton("close");
        close.addActionListener(new ActionListener() { // implementing actionlistener
            public void actionPerformed(ActionEvent ae) {       
                Window w = (Window)Frame.getFrames()[0];        
                WindowListener listener = w.getWindowListeners()[0];        
                listener.windowClosing(new WindowEvent(w, 0));
            }
        });
        p.add(close);   
        getContentPane().add(p);   // adding pane to container 
    }       
}

/* HERE RUNTIME ERROR I AM GETTING. HOW TO REMOVE IT

Exception in thread "Thread-3" java.security.AccessControlException: access deni
ed (java.lang.RuntimePermission exitVM)
        at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:264)
        at java.security.AccessController.checkPermission(AccessController.java:
427)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
        at java.lang.SecurityManager.checkExit(SecurityManager.java:744)
        at java.lang.Runtime.exit(Runtime.java:88)
        at java.lang.System.exit(System.java:869)
        at sun.applet.AppletViewer.appletSystemExit(AppletViewer.java:836)
        at sun.applet.AppletViewer.access$400(AppletViewer.java:101)
        at sun.applet.AppletViewer$3.run(AppletViewer.java:824)
        at java.lang.Thread.run(Thread.java:595)

*/
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
radha
  • 1
  • 3
  • Why are you stuffing about with this nonsense? If you want to close the applet viewer, click the little `X` button on the upper right of the frame. This custom close button of yours is no use whatsoever to the end user, so stop wasting time. – Andrew Thompson Apr 23 '14 at 06:52
  • yes Mr Andrew Thompson you are write, my manager told me to add a button close button to applet,that button has to do "X" button work i.e it has to close appletviewer. – radha Apr 23 '14 at 07:18
  • Mr.Andrew Thompson can u suggest me few sites where i can learn java,applet,swings.servelets (related to java devolopper).please – radha Apr 23 '14 at 07:20
  • *"my manager told me to add a button close button to applet"* I don't give a stuff what your manager wants. I want to hear their (sensible) reason as to ***why*** it makes any sense to do this. You might have the attitude that 'the boss saying so' is good enough, but they are not *my* boss and it is not good enough. – Andrew Thompson Apr 23 '14 at 08:11
  • Mr. Andrew Thompson thanks for the reply.just now manager told me,that he wanted, me to learn the code stuff behind the closing button on apllet and some java.policy file related things.now i am leaving this topic. – radha Apr 23 '14 at 08:47

0 Answers0