Hi everybody!

I made an applet, and was trying to put it in web page. When I run my applet by itself it works fine, but when I'm trying to run it thrue the web page it doesn't work at all. I mean I have just grey box (like a JFrame) but nothing inside.

here is the code of applet:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonApplet  extends JApplet {

    private static JButton button1 = new JButton("SOUTH");
    private static JButton button2 = new JButton("NORTH");
    private static JLabel label = new JLabel(); 

    public void init() {

        Listener listener = new Listener();

        button1.addActionListener(listener);
        button2.addActionListener(listener);

        this.getContentPane().add(button1, BorderLayout.SOUTH);
        this.getContentPane().add(label, BorderLayout.CENTER);
        this.getContentPane().add(button2, BorderLayout.NORTH);

    }

    private class Listener implements ActionListener {


        public void actionPerformed(ActionEvent e) {
            String actionCommand = e.getActionCommand();
            if(actionCommand == "SOUTH")
                label.setText("You pressed SOUTH button");
            if(actionCommand == "NORTH")
                label.setText("You pressed NORTH button");

        }
    }
}

and here is the html source:

<h2> This is my first applet </h2>
<applet code="ButtonApplet.class" width=300 height=100>
</applet>

Recommended Answers

All 8 Replies

Did you upload the .class file to the same directory as the HTML file?

also, does your host support java(applets)?
it's an issue i had.

Where there any error messages in the browser's java console?

Well, when I run this html file, my browser says at the buttom:

Start: applet not initialized

Where there any error messages in the browser's java console?

No, not at all, I even tryed to put some try catch blocks, but still no error. Coudl it be problem with browser? or some thing like that, because like I said applet works fine when I run it in Eclipse.

did you enable your java plug-in in your browser?

I tried the program in HTML and got it to work...

I'm glad at least it works, but not on my computer... =)
And yeas I just checked and reinstall IsedTea plugin. I tryed it in Firefox and Chrom. =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.