Netbeans の JUNG ライブラリを使用して、正常にコンパイルおよび実行される JApplet を作成しました。しかし、アプレットを実行する html ファイルを作成しようとすると、グレーのペインしか表示されず、コンポーネントが表示されません。私のクラスは:
public class View extends JApplet {
//Here I declare the buttons etc..
public View()
{
initializeComponent();
fetchGraphs();
}
public static void main(String[] args) throws IOException{
f = new JFrame();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
x = screenSize.width;
y = screenSize.height;
f.getContentPane().add(new View());
f.setTitle("Social Network Privacy Settings and Access Control");
f.setLocation(new Point(15, 20));
f.setSize(new Dimension(x-20,y-50));
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setResizable(false);
f.setVisible(true);
}
}
メソッド initializeComponent() は、すべてのコンポーネントをメイン ウィンドウに追加します。JFrameBuilder を使用して、いくつかの基本的なコンポーネントを作成しました。JFrameBuilder はメソッド addComponent(container, component, x, y, width, height) を使用してコンポーネントを追加します
そのために以下のコードを使用します。
contentPane = (JPanel)this.getContentPane();
//to create the japplet contentpane
addComponent(contentPane, genGraphButton, (int)(0.35*x),(int)(0.63*y),
(int)(0.2*x),28);
// to add components
次に、html ファイルを作成します。
<applet code = 'MyPackage.View'
archive = 'MyProject.jar',
width = 1600,
height = 800/>
/dist フォルダーにありますが、Mozilla Firefox で開こうとすると灰色のペインしか表示されません。奇妙なことに、別の単純なアプレットを作成しました。今回は netbeans JBuilder を使用し、Web ページで正常に実行されます。
本当に助けが必要です!