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>