【发布时间】:2014-10-31 14:16:36
【问题描述】:
我正在尝试使用 IntelliJ 设置一个简单的JApplet。我有一个名为Square 的类和一个应该使它工作的HTML 文件,但我不断收到ClassNotFoundException。
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>
这是文件夹结构。我尝试了很多不同的组合和名称以及 分隔符,但我无法正确打开它。
【问题讨论】:
标签: java swing intellij-idea applet