我有一个打包到jar中的applet虽然它运行(在控制台中显示打印语句测试)但它只显示一个空白屏幕。
以下是applet代码:
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
public class Test extends JApplet {
JLayeredPane frame = new JLayeredPane();
JButton button = new JButton("Test");
JLabel backgroundLabel;
public void init() {
button.setBounds(10, 10, 100, 40);
backgroundLabel = new JLabel(){
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.setPaint(new GradientPaint(
new Point(0, 0),
new Color(90, 207, 233),
new Point(0, getHeight()),
Color.white));
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.dispose();
}
};
backgroundLabel.setBounds(0, 0, getWidth(), getHeight());
frame.add(backgroundLabel, new Integer(0));
frame.add(button, new Integer(1));
add(frame);
}
}
这是html代码:
<applet
id="clientApplet"
codebase="test"
code="Test.class"
archive="test.jar"
width="820" height="600">
Your browser does not support the <code>applet</code> tag.
</applet>
applet在Eclipse中运行良好,并且控制台中不会显示任何错误。任何人都可以说问题可能是什么?
答案 0 :(得分:0)
似乎更新已阻止<applet>
代码正常运行。我用<embed>
替换它,现在一切都很好。
<embed id="test"
type="application/x-java-applet;version=1.6"
width="256" height="256"
archive="test.jar"
code="Test.class"
codebase="test"
pluginspage="http://java.com/download/"
myParam="" />