Only language I can't even get HelloWorld to work


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: Only language I can't even get HelloWorld to work

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Posts
    6

    Only language I can't even get HelloWorld to work

    so what I'm looking to eventually do is make a 3d plugin and adapt a T3d file format reader that I wrote in C years ago and make a little virtual world where I can try out some game ideas, but I can't even get the hello world to work.

    I first tried a google search for 3d java apps but all the info I found was really offbase. So I went to sun and started with the applet tutorials. they started giving code for a hello world but made no mention of how to actually use it. so I looked at the source code and saw something like

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

    so i tried that and made HelloWorld.class with their sourcecode in it and all I got in firefox was a box with a red x in it.

    So then I tried to view their source that was actually in HelloWorld.class but it was filled with jibberish, nulls, strange symbols and all sorts of weirdness with the only thing in english was path variables.


    I got the same thing here http://javaboutique.internet.com/tutorials/Step/

    so I'm at a loss. How do I actually create a helloworld program?

    I haven't done regular java programming (non applet) in years and never really understood it. I could never get OO down at all. Every book I read said that it was closer to the way we really think then procedural but it's too alien to me.

    The most I've ever been able to do was some simple database programs.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    What you have looked at is how to invoke the applet tag in a HTML page, not the code for the applet itself. Take a look here:

    http://java.sun.com/docs/books/tutor...oyment/applet/

    and the first thing you find is:

    import javax.swing.JApplet;
    import java.awt.Graphics;

    public class HelloWorld extends JApplet
    {
    public void paint(Graphics g)
    {
    g.drawRect(0, 0,
    getSize().width - 1,
    getSize().height - 1);
    g.drawString("Hello world!", 5, 15);
    }
    }

  3. #3
    Join Date
    Apr 2008
    Posts
    6

    code

    yup thats whats in my .class file
    thats what I meant when i said "so i tried that and made HelloWorld.class with their sourcecode in it and all I got in firefox was a box with a red x in it."
    sorry i didn't post what code was in it. I wasn't very clear.

  4. #4
    Join Date
    Apr 2008
    Posts
    6
    oh i should mention that I tried the just hello world one first and it didnt work either. im still reading up about the topics im trying to cover (3d, backbuffering, overall java programming), but the first step itself is a bit hard

  5. #5
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Sounds like your applet tag did not know where to find your class file. Think about using the CODEBASE attribute.

  6. #6
    Join Date
    Apr 2008
    Posts
    6

    help

    I put it in but I'm not sure if I'm using it correctly. I thought it might hep if I include a pic.

    http://www.sirus20x6.com/help.png

  7. #7
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    I suggest you post your Java applet code and the source for the HTML page including the APPLET tag you are using

  8. #8
    Join Date
    Apr 2008
    Posts
    6

    java

    Well it's in the pic but here goes.
    in my html file i have:

    <html>
    <head></head>
    <body>
    <applet code="rect.class" CODEBASE="/" width="200" height="200">
    </applet>
    </body>
    </html>

    and in my rect.class file i have:
    import javax.swing.JApplet;
    import java.awt.Graphics;

    public class HelloWorld extends JApplet
    {
    public void paint(Graphics g)
    {
    g.drawRect(0, 0,
    getSize().width - 1,
    getSize().height - 1);
    g.drawString("Hello world!", 5, 15);
    }
    }

    and they are both in the same folder.
    I seem to be able to use other applets on the net. I just can't get mine to work.

  9. #9
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    When I tried to view your attached file, before, some other page displayed rather than your png file. On a different computer I can now view your graphic showing the display of the html file and your two sources.

    Does it run in the applet viewer? See

    http://java.sun.com/j2se/1.3/docs/to...letviewer.html


    By the way ... did you write a rect.java file which has been compiled into a rect.class file before you attempt to run the applet by loading the page?
    Last edited by nspils; 04-10-2008 at 09:42 PM.

  10. #10
    Join Date
    May 2004
    Posts
    40

    Only language I can't even get HelloWorld to work

    I hate to ask the obvious, but you keep saying that your class file contains
    Code:
    import javax.swing.JApplet;
    import java.awt.Graphics;
    
    public class HelloWorld extends JApplet
    {
    public void paint(Graphics g)
    {
    g.drawRect(0, 0,
    getSize().width - 1,
    getSize().height - 1);
    g.drawString("Hello world!", 5, 15);
    }
    }
    Have you actually compiled this java code into a class file?

    alan

Similar Threads

  1. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 06:32 PM
  2. Replies: 10
    Last Post: 03-11-2002, 06:41 PM
  3. Enough Language Bigotry!
    By Nollen in forum .NET
    Replies: 94
    Last Post: 02-23-2001, 12:44 PM
  4. Replies: 8
    Last Post: 02-12-2001, 01:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center