我刚刚在netbeans中制作了一个applet。但是当我尝试使用jar文件到达它时,它会给我一个Class not found异常错误。以下是错误的详细信息:
Java Plug-in 10.45.2.18 使用JRE版本1.7.0_45-b18 Java HotSpot(TM)客户端VM
c:清除控制台窗口 f:在终结队列上完成对象 g:垃圾收集 h:显示此帮助信息 l:转储类加载器列表 m:打印内存使用情况 o:触发日志记录 问:隐藏控制台 r:重新加载策略配置 s:转储系统和部署属性 t:转储线程列表 v:转储线程堆栈 x:清除类加载器缓存
0
Exception in thread "AWT-EventQueue-4" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkExit(Unknown Source)
at java.lang.Runtime.exit(Unknown Source)
at java.lang.System.exit(Unknown Source)
at TicTacToe$ButtonListener.runAI(TicTacToe.java:155)
at TicTacToe$ButtonListener.actionPerformed(TicTacToe.java:105)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
以下是html的代码。
<html>
<head>
<title>Minigames for All</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h2 id="header">Welcome to Minigames for All.</h2>
<hr>
<div id="script">
<object type="application/x-java-applet" height="300" width="550">
<param name="code" value="slime2" />
<param name="archive" value="applet/slime2.jar" />
Applet failed to run. No Java plug-in was found.
</object>
</div>
<hr>
<table>
<tbody>
<tr>
<td><a href="rps.html">Rock, Paper, Scissors</td>
<td><a href="random.html">Guess the Number</td>
<td><a href="ttt.html">Tic Tac Toe</td>
</tr>
<tr>
<td><a href="flip.html">Flip a Coin</td>
<td><a href="rpg.html">Slime RPG</td>
<td><a href="shoot.html">Space Shooter</td>
</tr>
<tr>
<td> </td>
<td><a href="index.html">Home Page</td>
<td> </td>
</tr>
</tbody>
</table>
</body>
</html>
以下是applet的代码:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Random;
/**
*
* @author C.C
*/
public class slime extends javax.swing.JApplet {
Random rng = new Random();
int choice;
int player = 100;
int king = 100;
int slime = 50;
/**
* Initializes the applet slime
*/
@Override
public void init() {
choice = rng.nextInt(10)+1;
if(choice >=7)
{
battle.append("You are the hero. You have 100 health." + "\n");
battle.append("You encountered a King Slime!" + "\n\n");
}
else
{
battle.append("You are the hero. You have 100 health." + "\n");
battle.append("You encountered a slime!" + "\n\n");
}
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(slime.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(slime.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(slime.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(slime.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the applet */
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* This method is called from within the init() method to initialize the
* form. WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
battle = new javax.swing.JTextArea();
attack = new javax.swing.JButton();
heal = new javax.swing.JButton();
charge = new javax.swing.JButton();
run = new javax.swing.JButton();
battle.setColumns(20);
battle.setRows(5);
jScrollPane1.setViewportView(battle);
attack.setText("Attack");
attack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
attackActionPerformed(evt);
}
});
heal.setText("Heal");
heal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
healActionPerformed(evt);
}
});
charge.setText("Charge");
charge.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chargeActionPerformed(evt);
}
});
run.setText("Run");
run.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
runActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(heal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(attack, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(charge, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
.addComponent(run, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(attack)
.addComponent(charge))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(heal)
.addComponent(run))
.addContainerGap())
);
}// </editor-fold>
private void attackActionPerformed(java.awt.event.ActionEvent evt) {
int damage = rng.nextInt(10)+1;
int damage2 = rng.nextInt(25)+10;
int damage3 = rng.nextInt(20)+5;
if(player <= 0)
{
battle.append("You have died" + "\n\n");
System.exit(0);
}
else
{
if(damage >=7)
{
battle.append("You did "+ String.valueOf(damage)+ " damage. It was a critcal hit!" + "\n");
if (choice >=7)
{
king = king-damage;
battle.append("The King Slime has " + king + " health left!" + "\n");
if(king <=0)
{
battle.append("You have defeated the King Slime!" + "\n\n");
System.exit(0);
}
battle.append("The King Slime hit you for " + String.valueOf(damage2) + " damage!" + "\n");
player = player-damage2;
if(player < 0)
{
player = 0;
}
battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
}
else
{
slime = slime-damage;
battle.append("The slime has " + slime + " health left!" + "\n");
if(slime <=0)
{
battle.append("You have defeated the slime!" + "\n\n");
System.exit(0);
}
battle.append("The slime hit you for " + String.valueOf(damage3) + " damage!" + "\n");
player = player-damage3;
if(player < 0)
{
player = 0;
}
battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
}
}
else
{
battle.append("You did "+ String.valueOf(damage)+ " damage." + "\n");
if (choice >=7)
{
king = king-damage;
battle.append("The King Slime has " + king + " health left!" + "\n");
if(king <=0)
{
battle.append("You have defeated the King Slime!" + "\n\n");
System.exit(0);
}
battle.append("The Slime King hit you for " + String.valueOf(damage2) + " damage!" + "\n");
player = player-damage2;
if(player < 0)
{
player = 0;
}
battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
}
else
{
slime = slime-damage;
battle.append("The slime has " + slime + " health left!" + "\n");
if(slime <=0)
{
battle.append("You have defeated the slime!" + "\n\n");
System.exit(0);
}
battle.append("The slime hit you for " + String.valueOf(damage3) + " damage!" + "\n");
player = player-damage3;
if(player < 0)
{
player = 0;
}
battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
}
}
}
}
private void healActionPerformed(java.awt.event.ActionEvent evt) {
int heal = rng.nextInt(40)+20;
int damage2 = rng.nextInt(25)+10;
int damage3 = rng.nextInt(20)+5;
if(player <= 0)
{
battle.append("You have died" + "\n\n");
System.exit(0);
}
else
{
battle.append("You healed for " + heal + " health.\n");
player = player+heal;
if (choice >=7)
{
battle.append("The King Slime has " + king + " health left!" + "\n");
battle.append("The King Slime hit you for " + String.valueOf(damage2) + " damage!" + "\n");
player = player-damage2;
if(player < 0)
{
player = 0;
}
battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
}
else
{
battle.append("The slime has " + slime + " health left!" + "\n");
battle.append("The slime hit you for " + String.valueOf(damage3) + " damage!" + "\n");
player = player-damage3;
if(player < 0)
{
player = 0;
}
battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
}
}
}
private void chargeActionPerformed(java.awt.event.ActionEvent evt) {
int damage = rng.nextInt(30)+10;
int damage2 = rng.nextInt(25)+10;
int damage3 = rng.nextInt(20)+5;
if(player <= 0)
{
battle.append("You have died" + "\n\n");
System.exit(0);
}
else
{
battle.append("You skip a turn to charge a more powerful attack!" +"\n");
if (choice >=7)
{
battle.append("The King Slime has " + king + " health left!" + "\n");
battle.append("The King Slime hit you for " + String.valueOf(damage2) + " damage!" + "\n");
player = player-damage2;
if(player < 0)
{
player = 0;
}
battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
}
else
{
battle.append("The slime has " + slime + " health left!" + "\n");
battle.append("The slime hit you for " + String.valueOf(damage3) + " damage!" + "\n");
player = player-damage3;
if(player < 0)
{
player = 0;
}
battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
}
if(player <=0)
{
battle.append("You have died" + "\n\n");
System.exit(0);
}
else
{
if (choice >=7)
{
battle.append("You unleash a powerful attack at the King Slime for " + damage + " damage.\n");
king = king-damage;
battle.append("The King Slime has " + king + " health left!" + "\n");
if(king <=0)
{
battle.append("You have defeated the King Slime!" + "\n\n");
System.exit(0);
}
battle.append("The King Slime hit you for " + String.valueOf(damage2) + " damage!" + "\n");
player = player-damage2;
if(player < 0)
{
player = 0;
}
battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
}
else
{
battle.append("You unleash a powerful attack at the slime for " + damage + " damage.\n");
slime = slime-damage;
battle.append("The slime has " + slime + " health left!" + "\n");
if(slime <=0)
{
battle.append("You have defeated the slime!" + "\n\n");
System.exit(0);
}
battle.append("The slime hit you for " + String.valueOf(damage3) + " damage!" + "\n");
player = player-damage3;
if(player < 0)
{
player = 0;
}
battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
}
}
}
}
private void runActionPerformed(java.awt.event.ActionEvent evt) {
battle.append("You can't run in this game you sissy.\n\n");
}
// Variables declaration - do not modify
private javax.swing.JButton attack;
private javax.swing.JTextArea battle;
private javax.swing.JButton charge;
private javax.swing.JButton heal;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton run;
// End of variables declaration
}
答案 0 :(得分:2)
您收到了AccessControlException
异常,这意味着不允许进行操作。
您不应该在applet中调用System.exit()
。通常不允许小程序执行它。当System.exit()
终止JVM时,您可以终止当前在浏览器中运行的其他小程序。有关详细信息,请参阅What Applets Can and Cannot Do。
重新设计applet以导航到指示applet执行结束的文档。您可以使用applet.getAppletContext().showDocument()
来实现此目的。