Java applet无法加载 - Error.click了解详细信息

时间:2014-10-30 20:23:55

标签: java applet

我一直在尝试使用Java。我从一本书中得到了一个示例小程序 Cay Horstmann和Gary Cornell的核心Java。

我已经尝试了几个选项来打开它,但我一直收到错误Error.click for details。然后Application blocked. Click for details Your security settings blocked application from running

我无法从IE或Mozilla运行它。在Netbeans中,我收到no main class found通知。

我想知道代码或我的设置是否有问题。

我将不胜感激。

这是我的WelcomeApplet.java文件:

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;

/**
 * This applet displays a greeting from the authors.
 * @version 1.22 2007-04-08
 * @author Cay Horstmann
 */
public class WelcomeApplet extends JApplet
{
   public void init()
   {
  EventQueue.invokeLater(new Runnable()
     {
        public void run()
        {
           setLayout(new BorderLayout());

           JLabel label = new JLabel(getParameter("greeting"), SwingConstants.CENTER);
           label.setFont(new Font("Serif", Font.BOLD, 18));
           add(label, BorderLayout.CENTER);

           JPanel panel = new JPanel();

           JButton cayButton = new JButton("Cay Horstmann");
           cayButton.addActionListener(makeAction("http://www.horstmann.com"));
           panel.add(cayButton);

           JButton garyButton = new JButton("Gary Cornell");
           garyButton.addActionListener(makeAction("mailto:gary_cornell@apress.com"));
           panel.add(garyButton);

           add(panel, BorderLayout.SOUTH);
        }
     });
   }

   private ActionListener makeAction(final String urlString)
   {
      return new ActionListener()
         {
            public void actionPerformed(ActionEvent event)
            {
               try
               {
                  getAppletContext().showDocument(new URL(urlString));
               }
               catch (MalformedURLException e)
               {
                  e.printStackTrace();
               }
            }
         };
   }
}

然后applet代码WelcomeApplet.html:

<html>
   <head>
      <title>WelcomeApplet</title>
       </head>
   <body>
      <hr/>
      <p>
         This applet is from the book 
         <a href="http://www.horstmann.com/corejava.html">Java. Podstawy</a>, 
         with authors <em>Cay Horstmann</em> and <em>Gary Cornell</em>,
         wydanej przez wydawnictwo Helion.
      </p>
  <applet code="WelcomeApplet.class" width="400" height="200">
     <param name="greeting" value="Witaj, czytelniku!"/>
  </applet>
  <hr/>
  <p><a href="WelcomeApplet.java">Source.</a></p>

还有其他文件java.policy.applet

/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
/* DO NOT EDIT */

grant {
  permission java.security.AllPermission;
};

0 个答案:

没有答案