简体   繁体   中英

Applet Shows Blank Screen in Browser

I have an applet that is packaged into a jar which although it runs (tested with print statements showing in console) it displays only a blank screen.

Here is the applet code:

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);
    }
}

And this is the html code:

<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>

The applet works fine in Eclipse and no errors show up in the console. Can anyone please say what the problem might be?

It seems that an update has stopped the <applet> tag from functioning. I replaced it with <embed> and all is fine now.

<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="" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM