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


        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>

Edited by Ezzaral: Fixed code formatting.

4 Years
Discussion Span
Last Post by shean1488

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

Start: applet not initialized


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

Edited by zeroliken: added info


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. =)

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.