2015-02-23 55 views
0

當我在Eclipse(Luna,java vers = 8)上運行以下代碼時,代碼將運行並彈出兩條錯誤消息。另一方面,當我在html頁面中嵌入代碼時,代碼只顯示第一條錯誤消息。看起來調用ForkJoinPool類會壓縮firefox上的applet。 你知道爲什麼嗎?這是代碼。Java - 當使用ForkJoinPool時(在Eclipse中工作時),Applet不能在Firefox上工作

import java.awt.BorderLayout; 
import java.awt.Container; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.util.concurrent.ForkJoinPool; 

import javax.swing.JApplet; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JOptionPane; 
import javax.swing.JPanel; 
import javax.swing.SwingUtilities; 

public class ProvaVera extends JApplet 
{ 
    public void start() 
    { 

     SwingUtilities.invokeLater(new Runnable(){ 
     public void run() 
      { 
       MainPanel panel = new MainPanel();  
       // Add Swing components to content pane 
       Container c = getContentPane(); 
       c.add(panel, BorderLayout.CENTER); 
      } 
     }); 

    } 

} 
class MainPanel extends JPanel 
{ 

    public MainPanel() 
    { 
     JLabel label1 = new JLabel("label1"); 
     this.add(label1); 
     JButton btn1 = new JButton("button1"); 
     this.add(btn1); 

     btn1.addActionListener (
       new ActionListener() 
       { 
        public void actionPerformed(ActionEvent e) 
        { 
         metodo(); 
        } 
       } 

       ); 
    } 



    public void metodo() 
    { 
     JOptionPane.showMessageDialog(new JFrame(), "test1", "Dialog", JOptionPane.ERROR_MESSAGE); 
     ForkJoinPool pool = new ForkJoinPool(); 
     JOptionPane.showMessageDialog(new JFrame(), "test2", "Dialog", JOptionPane.ERROR_MESSAGE); 
    } 
} 

回答

0

我已經從java控制面板啓用了Java控制檯。 和錯誤是: java.security.AccessControlException:訪問被拒絕( 「java.lang.RuntimePermission」 「modifyThread」)

所以我去了位於java.home我java.policy文件/ lib/security中/我寫了以下內容

grant codeBase "url or file where the applet is" { 
permission java.lang.RuntimePermission "modifyThread"; 
}; 

現在小程序正在工作。

再次感謝您的支持。

0

您可能會遇到安全異常,因爲ForkJoinPool需要'modifyThread'運行時權限。

當您在Eclipse中運行時,沒有安裝安全管理器,因此您不會遇到安全異常。當你在瀏覽器中運行時,有一個嚴格的安全管理器。

+0

感謝您的回答,我該如何解決這個問題? – user2282064 2015-02-24 11:06:54