user3109881
user3109881

Reputation: 1

Hello World Java Applet Won't display in Firefox for Ubuntu

Hi guys I'm having some trouble running my first applet on Java. I'm pretty new to Ubuntu but here's what I have so far.... For my HelloWorldApplet.java file:

import java.awt.Graphics;

public class HelloWorldApplet extends java.applet.Applet{

public void paint(Graphics g) {

    g.drawString("Hello World!",5,25);
}



}

Then I compiled it into a HelloWorldApplet.class file. Here is my html code:

<HTML>
<HEAD>
<TITLE> Hello to Everyone!</TITLE>
</HEAD> <BODY>
<body bgcolor = red>
<P> My Java applet says:
<APPLET CODE="HelloWorldApplet.class" WIDTH=150 HEIGHT=25>

</BODY>
</HTML>

When I try to open it with mozilla firefox, it doesn't display the hello world message it only has "My Java applet says:" With the red background.

I've also ran this java code as a application and it works fine. When I try to run it using appletviewer it works about half the time... Sometime I would see the applet window with the text and sometimes nothings happen and I don't even get an error sign, it's so strange. Can anyone please give me some ideas for why I can't get the applet to work?

Thanks!!

Upvotes: 0

Views: 926

Answers (2)

Martin Frank
Martin Frank

Reputation: 3454

It is hard to identify the source of your problem...

  • maybe it's because you don't guarantee a redraw on start()?
  • maybe it's because your screen isn't properly drawn (super.paint)?
  • maybe your colors are not set properly?

try some of those tweak...

public class YourApplet extends JApplet{
    public YourApplet() throws HeadlessException {

    @Override
    public void init() {
        super.init();
        setBackground(Color.WHITE);
    }
    @Override
    public void start() {
        super.start();
        repaint();
    }
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.setColor(Color.BLACK);
        g.drawString("Hello World!",5,25);
    }

}

Upvotes: 0

Buddhima Gamlath
Buddhima Gamlath

Reputation: 2328

Try installing icedtea-plugin and restarting the browser.

sudo apt-get install icedtea-plugin

Upvotes: 1

Related Questions