Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: Snake X on March 08, 2011, 09:19:45 pm

Title: setting up java applet?
Post by: Snake X on March 08, 2011, 09:19:45 pm
??? has anyone ever set up a java applet successfully before? I need help. I have my html file for the applet hosted here: http://greyshadowencodes.webs.com/car.html

and I HAVE the applet (IT IS a .class file, trust me it is I know it has to be .class and compiled which it is) in the same root directory as the car.html file (the page where the applet should be running) and it gives me an error which I don't get. Can anyone help me?

I'll even upload my .java file and you can view source of my link i posted if you need to.
Title: Re: setting up java applet?
Post by: z80man on March 08, 2011, 09:27:03 pm
Try this
Code: [Select]
<applet
     codebase = "."
     code = "car.class"
     name = "Car"
     width = "600"
     height = "600"
     hspace = "0"
     vspace = "0"
     align = "middle"

>

</applet>
Title: Re: setting up java applet?
Post by: Snake X on March 08, 2011, 09:28:58 pm
:( no that didn't work either. umm ill try lowercase 'car' under name

edit: :( still didn't work. you can just refresh the page if you wanna see

edit edit: I am working in a webs account if that helps
Title: Re: setting up java applet?
Post by: jnesselr on March 08, 2011, 10:23:32 pm
It's not your html at all.  You need to read up more on how to do applets.  I suggest you look at this (http://download.oracle.com/javase/tutorial/deployment/applet/index.html).  I also like compiling into .jar even if it is one class.  It keeps things all neat and tidy to me.  Add this to your code: (It's just another method like paint.  It initializes the app.  It also might be good to call super.paint(g) just in case the super class needs to paint something.  This is because the paint method goes all the way back to java.awt.Container.  It is explained fairly well here (http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Container.html#paint(java.awt.Graphics)).

Code: [Select]
    public void init() {
        super.init();
    }
Title: Re: setting up java applet?
Post by: Munchor on March 11, 2011, 01:06:48 pm
Code: [Select]
<p align="center">
<applet code="MainClass.class" width="640" height="640" alt="Applet GUIDemo demonstrates some basic GUI components">
<div align="center">
<p>
<b>Java is not enabled in your browser</b>
</applet></p>
1. I know this code is XHTML wrong, but I don't use XHTML;
2. The problem is probably the class file;
3. This works great for me (with functional applets classes) so try it too.