0
我正在嘗試使用IntelliJ設置一個簡單的JApplet
。我有一個名爲Square
的類和一個HTML文件,它應該能夠正常工作,但我一直得到ClassNotFoundException
。ClassNotFound在調用Applet時發生異常
import javax.swing.*;
import java.awt.*;
public class Square extends JApplet {
int size = 40;
public void init() {
JButton butSmall = new JButton("Small");
JButton butMedium = new JButton("Medium");
JButton butLarge = new JButton("Large");
JButton butMessage = new JButton("Say Hi!");
SquarePanel panel = new SquarePanel(this);
JPanel butPanel = new JPanel();
butPanel.add(butSmall);
butPanel.add(butMedium);
butPanel.add(butLarge);
butPanel.add(butMessage);
add(butPanel, BorderLayout.NORTH);
add(panel, BorderLayout.CENTER);
}
}
class SquarePanel extends JPanel {
Square theApplet;
SquarePanel(Square app) {
theApplet = app;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.green);
g.fillRect(20, 20, theApplet.size, theApplet.size);
}
}
和HTML文件
<HTML>
<APPLET CODE="Square.class"> WIDTH=400 HEIGHT=200>
</APPLET>
</HTML>
這是文件夾結構。我嘗試了很多不同的組合和名稱,並嘗試了很多分隔符,但我無法正確打開它。
參見[*爲什麼CS教師應停止教學Java小程序*](HTTP://程序員.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets /)和[*初始線程*](http://docs.oracle.com/javase/tutorial/uiswing/併發/ initial.html)。 – trashgod 2014-10-31 17:43:37