Hello,
The following shows two ways to put the applet tag parameters into an html web page.
The first reads the classes from the directory specified in the codebase attribute of the applet tag.
In this example, codebase ="." which means the current directory or the directory where the html web page is.
The second uses the archive attribute where
archive = "AlkaSeltzerApplet.jar"
You create this jar archive with the command:
jar cvf AlkaSeltzerApplet.jar *class
The AlkaSeltzerApplet.jar must be in the same directory as the web page since codebase = "."
You can change it to whatever you need.
I wrote this little applet because it has three inner classes which when compiled produces 4 class files.
Putting them all in a jar file makes it convenient for uploading to a web server.
Some web servers such as Yahoo won't accept subclass files, so you have to put them in a jar archive.
So experiment with several options and see for your self which you like best.
<html>
<head>
<title>AlkaSeltzerApplet</title>
</head>
<body>
<applet
code="AlkaSeltzerApplet.class"
codebase ="."
width="300"
height="100">
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason."
Your browser is completely ignoring the <APPLET> tag!
</applet>
<applet
code="AlkaSeltzerApplet.class"
codebase ="."
archive = "AlkaSeltzerApplet.jar"
width="300"
height="100">
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason."
Your browser is completely ignoring the <APPLET> tag!
</applet>
</body>
</html>
******************************** ***********
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class AlkaSeltzerApplet extends Applet{
private TextField display;
public void init(){
Panel buttonPanel = new Panel();
Button plopPlopButton = new Button("PlopPlop!");
Button fizzFizzButton = new Button("FizzFizz");
Button reliefButton = new Button("Oh! What a relief it is!");
plopPlopButton.addActionListener(new PlopPlopAction());
fizzFizzButton.addActionListener(new FizzFizzAction());
reliefButton.addActionListener(new ReliefAction());
buttonPanel.add(plopPlopButton);
buttonPanel.add(fizzFizzButton);
buttonPanel.add(reliefButton);
setLayout(new BorderLayout());
add(buttonPanel, BorderLayout.NORTH);
display = new TextField();
add(display, BorderLayout.CENTER);
}
class PlopPlopAction implements ActionListener{
public void actionPerformed(ActionEvent actionEvent){
display.setText("Plop Plop!");
}
}
class FizzFizzAction implements ActionListener{
public void actionPerformed(ActionEvent actionEvent){
display.setText("Fizz! Fizz!");
}
}
class ReliefAction implements ActionListener{
public void actionPerformed(ActionEvent actionEvent){
display.setText("Oh! What a relief it is!");
}
}
}