The Artima Developer Community
Sponsored Link

Java Answers Forum
Help with applets and the object tag

1 reply on 1 page. Most recent reply: Jul 2, 2002 8:12 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Hiran

Posts: 41
Nickname: jclu
Registered: Mar, 2002

Help with applets and the object tag Posted: Jul 2, 2002 3:32 PM
Reply to this message Reply
Advertisement
I know this is a newbie question, but I'm a newbie when it comes to applets. Anyway, how do I insert my applet into an html page using the object tag? Also, what if my applet class compiles into three classes (because of inner classes), and relies on a bunch of other classes to perform its task? Most likely, all the compiled classes will be in the same directory as the html page.

I've searched around, but can't seem to find anything that can help me. I know there are tons of resources out there, but whatever I try doesn't seem to work. Please help. Thanks.
Hiran


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Help with applets and the object tag Posted: Jul 2, 2002 8:12 PM
Reply to this message Reply
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!");		
		}
	}
}

Flat View: This topic has 1 reply on 1 page
Topic: Download web Page from java application Previous Topic   Next Topic Topic: Runtime.getRuntime().exec()

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use