Helpful Information
 
 
Category: Java
Using Java Applets

I'm starting to get into the flow of Java, now all I need to do is find a way to incorperate it into my webpages. Do I use an <embed> tag, or what? I can't seem to find a definitive answer. I've seen tonnes of pages use these kind of applets before, so I'm just trying to jump onto the info-bahnwagon. (did I spell that right? anyway....)

Thanks again

tons .... bandwagon ** hehe


sorry bro .. i dont know much about java applets

Uh-huh... Well, err... Thanks.... :)

Hi

We can use the following 3 tags to deploy a Java Applet

1. <applet> - Suitable for multi-browser environment

2. <object> - Suitable for MS IE browser family

3. <embed> - Suitable for Mozilla browser family
--------------------------------------------------------------------------
Examples
1. <applet code=MyApplet.class width="200" height="200"></applet>

2. <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="200" height="200">
<PARAM name="code" value="MyApplet.class">
</OBJECT> *

3. <embed code="MyApplet.class"
width="200" height="200"
type="application/x-java-applet;version=1.6.0"
pluginspage="http://java.sun.com/javase/downloads"/>

* If you have any doubts abt the classid i've used plz check this link
http://java.sun.com/docs/books/tutorial/deployment/applet/objecttag.html


If you want a more detailed view about the deployment of applets in the web pages please check out the following sites:

1. http://java.sun.com/docs/books/tutorial/deployment/applet/deployindex.html

2. http://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html - Check out the deprecation issue of <applet> tag.

Hope this will give you some direction to your goal.

Regards

Code Exploiter

The object element alone can be used to run applets in at least MSIE, Opera, Netscape, and Firefox. See the Usenet thread How should I put an applet in a strict HTML page? (http://groups.google.co.uk/group/alt.html/browse_thread/thread/1a71a3fd69503de8/d4b02174e1cf3f16).

Mike

<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" height="196" width="460">
<param name="codebase" value="java">
<param name="code" value="panorama">
<param name="panorama" value="http://www.veiled-chameleon.com/images/hikes/grandeur-peak/grandeur-peak-full-circle.jpg">
<!--[if !IE]> -->
<object codebase="java" classid="java:panorama.class" height="196" width="460">
<param name="panorama" value="http://www.veiled-chameleon.com/images/hikes/grandeur-peak/grandeur-peak-full-circle.jpg">
</object>
<!-- <![endif]-->
</object>That should do it.

Thanks. I downloaded the program for sun overnight, and I can finally compile! (Believe me. That's not nearly as excited for you as it is for me :))

Again, thanks.

hi mike

I would suggest using Eclipse IDE (http://www.eclipse.org) for developing the programs. You can save your time a lot using this one.

Regards

Code Exploiter

http://www.veiled-chameleon.com/weblog/archives/000004.html (adapted for HTML)

That should do it.

That's inferior to what I posted. I believe we've discussed this in the past.

Mike

That's inferior to what I posted.Sorry, I didn't see your post.
I believe we've discussed this in the past.We have? :confused:

Sorry, I didn't see your post.

One of those things. :)



We have? :confused:

I'm pretty sure, yes ("I believe..."). If you've posted that link before, then I'm virtually certain.

Mike

I'm fairly positive I haven't, on this forum anyway. Search didn't turn anything up.

Can only certain Java programs work on the web? Because I tried using my "Hello World" program in a web page, but it didn't work.

Applets are constructed differently from applications, and they also have some security barriers in place to prevent harm to the user's computer (these restrictions can be applied to applications as well, but usually aren't).

Your applet needs to extend java.awt.Applet or javax.swing.JApplet, depending on your preferred toolkit. Instead of main(), various event-driven functions such as public void start(), public void init() are used, and obviously the only way to interact with the user is through a GUI (which you can paint onto the Applet or JApplet in the same way you'd use a Panel or JPanel) since there is no console available in the browser.

The default restrictions are mostly obvious things, like not being able to access the filesystem, but there are some less blatant ones as well, such as not being able to call System.exit(). Opening new Frames is allowed, but the frames will have a label somewhere on them saying "Java Applet Window."

No matter how hard I try, I cannot get this to work.

Here is my Java code:


class HelloWorldApp {
public static void start(String[] args) {
System.out.println("Test");
}
}

And the html:


<applet code=HelloWorldApp.class width="200" height="200"></applet>


??

class HelloWorldApp {
Your applet needs to extend java.awt.Applet or javax.swing.JApplet, depending on your preferred toolkit.

public static void start(String[] args) {
Instead of main(), various event-driven functions such as public void start()It's not static, and it doesn't have any arguments.

System.out.println("Test");
obviously the only way to interact with the user is through a GUI (which you can paint onto the Applet or JApplet in the same way you'd use a Panel or JPanel) since there is no console available in the browser.Nice end braces though. :)
class HelloWorldApp extends javax.swing.JApplet {
public void start() {
this.getContentPane().add(
new javax.swing.JLabel("Hello, world!")
);
}
}

You forgot to type [/code] lol

It still doesn't work....
My Java Console says the following:


load: class panorama.class not found.
java.lang.ClassNotFoundException: panorama.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\java\java\panorama\class.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 10 more

That's because you've copied the code directly from the example to which I linked, without modifying it for your applet. In fact, you should be using Mike's, which is, as he says, better.
For testing purposes only, though, your <applet> tag should do fine.

Nevermind, I got it to work :)










privacy (GDPR)