Olá galera, estou com problemas pra executar um applet.
O exemplo é do livro do Cay Horstmann, Big Java.
package appletbotao388;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
*
* @author Adm
*/
public class ButtonApplet extends Applet {
/** Initialization method that will be called after the applet is loaded
* into the browser.
*/
private Rectangle box;
private static final int BOX_X = 100;
private static final int BOX_Y = 100;
private static final int BOX_WIDTH = 20;
private static final int BOX_HEIGHT = 30;
public ButtonApplet()
{
box = new Rectangle(BOX_X,BOX_Y,BOX_WIDTH,BOX_HEIGHT);
final JTextField xField = new JTextField(5);
final JTextField yField = new JTextField(5);
JButton moveButton= new JButton("Mova");
class MoveButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
int x = Integer.parseInt(xField.getText());
int y = Integer.parseInt(yField.getText());
box.setLocation(x,y);
repaint();
}
}
JLabel xLabel = new JLabel("x = ");
JLabel yLabel = new JLabel("y = ");
JPanel panel = new JPanel();
panel.add(xLabel);
panel.add(xField);
panel.add(yLabel);
panel.add(yField);
panel.add(moveButton);
JFrame frame = new JFrame();
frame.setContentPane(panel);
frame.pack();
frame.show();
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.draw(box);
// TODO start asynchronous download of heavy resources
}
// TODO overwrite start(), stop() and destroy() methods
}
<HTML>
<HEAD>
</HEAD>
<BODY>
<applet code="ButtonApplet.class" width="300" height="300"></applet>
</BODY>
</HTML>
Os ButtonApplet.java, ButtonApplet.class e ButtonApplet.html estão na mesma pasta mas se eu tento abrir o html no firefox não aparece nada, fecho o firefox e quando tento abrir de novo fala que ele já está aberto e não está respondendo, aí lá vou eu pro ctrl + alt +del :D.
Se seleciono executar no .java no NetBeans (5.5) aparecem tanto a janela do applet quanto o JFrame, a função de mover o retângulo não funciona, mas as janelas aparecem.
É isso, se alguém puder me ajudar.