0

此代码用于在按下“关闭”按钮时关闭 appletviewer 窗口。它工作正常;但是,在关闭 appletviewer 窗口后会出现错误。

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)

*/
4

0 回答 0