Hi all,
I'm new to java applets. This is basically my first bigger applet. It works 100% fine when I run it in the applet viewer. As soon I start it in a web browser it stops working half way through. The code below is a short version of my applet. Its easier to understand and it reproduces what I see. Run it in the applet viewer first and than in a web-browser. I tried it in Firefox and internet explorer. Can anyone reproduce it and tell me how to fix that.

applet code:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ConfigApplet extends JApplet implements ActionListener{
	private String str;
    private JButton button;
    private JLabel l;
    private JComboBox box;
    JPanel p;
    public void init(){
    	p = new JPanel();
    	str = getParameter("text1");
    	if(str == null){
    		str = "abc";
    	}
    	p.setLayout(null);
        Font font = new Font("TimesRoman", Font.BOLD, 24);
        setFont(font);
        button = new JButton("Change String");
        button.setBounds(50, 100, 150, 30);
        button.addActionListener(this);
        p.add(button);
        l = new JLabel(str);
        l.setBounds(50, 50, 300, 30);
        p.add(l);
        String[]choices = new String[2];
        choices[0] = "next String";
        choices[1] = "another String";
        box = new JComboBox(choices);
        box.setVisible(false);
        box.setSelectedIndex(-1);
        box.setBounds(50, 100, 150, 30);
        box.addActionListener(this);
        p.add(box);
        Container content = getContentPane();
        content.add(p);
    }
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==button){
			str = getParameter("text2");
			button.setVisible(false);
			box.setVisible(true);
			if(str!=null){
				l.setText(str);
			}else{
				l.setText("damn that did not work");
			}
		}
		if(e.getSource()==box){
			l.setText((String)box.getSelectedItem());
		}
	}
}

html code:

<title>Applet Test Page</title>
<h1>Applet Test Page</h1>
<applet
	code="ConfigApplet.class"
	name="ConfigApplet" width="700" height="700">
	<PARAM NAME=text1 VALUE="This is the text I displayed">
	<PARAM NAME=text2 VALUE="This is the changed text I display now">
</applet>

Sorry for the format of the code. Did not know how to post code properly.

OK I figured what my problem is. It has nothing to do with coding. apparently my applet is accessing files on the computer and for that the applet has to be signed to verify its not malicious.

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.