1
我有一個打包成jar的applet,雖然它運行(用控制檯中顯示的打印語句測試),但它只顯示一個空白屏幕。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>
小應用程序工作正常,在Eclipse和沒有錯誤在控制檯中顯示出來。任何人都可以請說出問題可能是什麼?
'JLayeredPane frame..'對於JLayeredPayne的實例來說這是一個非常糟糕的名字。從名字來看,我曾預期過一個'JFrame'。 –