Problema com Applet

4 respostas
julianofischer

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
}
Esse é o código do applet.
<HTML>
<HEAD>
</HEAD>
<BODY>
<applet code="ButtonApplet.class" width="300" height="300"></applet>
</BODY>
</HTML>
Esse é o arquivo html. :D

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.

4 Respostas

julianofischer

Alguém me ajuda pessoal!

Luiz_Junior

algum tempo atrás passei por um problema semelhante quando executava o applet o mesmo não era exibido, mas era um problema no firefox baixei o jre e criei um link simbolico no linux e funcionou.

julianofischer

E o que é um link simbólico Luiz?

Luiz_Junior

Aqui explica e mostra passo a passo como fazer talvez te ajude.

http://www.java.com/pt_BR/download/help/linux_install.xml#install

Criado 7 de abril de 2008
Ultima resposta 10 de abr. de 2008
Respostas 4
Participantes 2