Java Applet

With NetBeans 6.7

Page 1 of 1

10 Replies - 2903 Views - Last Post: 14 July 2009 - 06:30 PM Rate Topic: -----

#1 Korupt   User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 185
  • Joined: 22-June 08

Java Applet

Posted 14 July 2009 - 11:09 AM

I'm coming from a C, C++, and C# base and I just started Java and the whole thing is just a bit weird for me. I'm trying to create web applet with NetBeans 6.7, first I tried with the Web Application template from NetBeans but that created a whole bunch of files with a main .jsp file with html in it so I didn't know what to do, where to put my applet code so I gave up on that. Then somewhere on a forum I read that you can make an applet with the regular Java Application template project from NetBeans, so that's what I made, put my applet code in the Main.java file and tried to build it and it does build but I get an exception and no output. Here's the applet code (it's from a tutorial example) :

/*
By Bavo Bruylandt (Http://www.realapplets.com")

*/

// and now The inevidable "Hello World" example :)/>

// tell the compiler where to find the methods you will use.
// required when you create an applet
import java.applet.*;
// required to paint on screen
import java.awt.*;


// the start of an applet - HelloWorld will be the executable class
// Extends applet means that you will build the code on the standard Applet class
public class Main extends Applet
{

// The method that will be automatically called  when the applet is started
     public void init()
     {
 // It is required but does not need anything.
     }


// This method gets called when the applet is terminated
// That's when the user goes to another page or exits the browser.
     public void stop()
     {
     // no actions needed here now.
     }


// The standard method that you have to use to paint things on screen
// This overrides the empty Applet method, you can't called it "display" for example.

     public void paint(Graphics g)
     {
 //method to draw text on screen
 // String first, then x and y coordinate.
      g.drawString("Hey hey hey",20,20);
      g.drawString("Hellooow World",20,40);

     }

}


and the errors:

run:
java.lang.NoClassDefFoundError: javaapplication2/Main
Caused by: java.lang.ClassNotFoundException: javaapplication2.Main
		at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
		at java.security.AccessController.doPrivileged(Native Method)
		at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
		at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
		at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
		at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
		at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: javaapplication2.Main.  Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)



Is This A Good Question/Topic? 0
  • +

Replies To: Java Applet

#2 NeoTifa   User is offline

  • NeoTifa Codebreaker, the Scourge of Devtester
  • member icon





Reputation: 4681
  • View blog
  • Posts: 19,530
  • Joined: 24-September 08

Re: Java Applet

Posted 14 July 2009 - 12:42 PM

Are you coding it yourself or are you cheating and using a predefined template?
Was This Post Helpful? 0
  • +
  • -

#3 Gasper   User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 66
  • Joined: 29-May 09

Re: Java Applet

Posted 14 July 2009 - 12:54 PM

hello :)

There's absolutely nothing wrong with your code.
Try to:
- compile the code into Main.class
- create new html file with tag <applet>
<applet code='Main.class' width='nnn' height='nnn'></applet>
<!----- Replace nnn with some numbers ------>



- run it with appletviewer or browser
appletviewer yourhtml.html




offtopic{<applet> tag now supported http://www.w3schools...tml5_applet.asp}
Was This Post Helpful? 0
  • +
  • -

#4 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java Applet

Posted 14 July 2009 - 02:18 PM

You are trying to run it as an application but it is an applet
Was This Post Helpful? 0
  • +
  • -

#5 Korupt   User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 185
  • Joined: 22-June 08

Re: Java Applet

Posted 14 July 2009 - 03:20 PM

View PostNeoTifa, on 14 Jul, 2009 - 01:42 PM, said:

Are you coding it yourself or are you cheating and using a predefined template?


Well I'm using the JavaApplication template from NetBeans. How would you go about coding it without an IDE?

View PostGasper, on 14 Jul, 2009 - 01:54 PM, said:

hello :)

There's absolutely nothing wrong with your code.
Try to:
- compile the code into Main.class
- create new html file with tag <applet>
<applet code='Main.class' width='nnn' height='nnn'></applet>
<!----- Replace nnn with some numbers ------>



- run it with appletviewer or browser
appletviewer yourhtml.html




offtopic{<applet> tag now supported http://www.w3schools...tml5_applet.asp}


Yeah I knew that, my question is how do I go about compiling it. Because right now when I click on Debug -> Debug Main Project I get a message saying "applet.Main class wasn't found in Applet project". The only way to get the thing to compile is to go to Debug -> Debug File which compiles the current file, but what if I wanna have a multi-file applet (as in multi-file source code).

This post has been edited by Korupt: 14 July 2009 - 03:21 PM

Was This Post Helpful? 0
  • +
  • -

#6 Gasper   User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 66
  • Joined: 29-May 09

Re: Java Applet

Posted 14 July 2009 - 03:41 PM

There are two options.
You can compile it using javac compiler in command line. I prefer this one.

And using NetBeans... {my computer's hardware is too week to run NetBeans, so this might not work}
New Project - > Java Application - > New File - > Java Class - > Paste your code
you can find your class file in NetBeansprojects/Yourproject/build/classes
Was This Post Helpful? 1
  • +
  • -

#7 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java Applet

Posted 14 July 2009 - 03:44 PM

Don't know Netbeans but you must have options:
- run as application
- run as applet
Was This Post Helpful? 1
  • +
  • -

#8 Korupt   User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 185
  • Joined: 22-June 08

Re: Java Applet

Posted 14 July 2009 - 03:55 PM

Awesome, thanks everybody for your help.
Was This Post Helpful? 0
  • +
  • -

#9 NeoTifa   User is offline

  • NeoTifa Codebreaker, the Scourge of Devtester
  • member icon





Reputation: 4681
  • View blog
  • Posts: 19,530
  • Joined: 24-September 08

Re: Java Applet

Posted 14 July 2009 - 06:25 PM

Well, first off, to make an applet without the template, you could just start a regular Java project (like I do) and make a class to extend JApplet. That's what cool kids do.
Was This Post Helpful? 0
  • +
  • -

#10 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java Applet

Posted 14 July 2009 - 06:28 PM

View PostNeoTifa, on 14 Jul, 2009 - 05:25 PM, said:

That's what cool kids do.

You are telling us your kids are cool :D
Was This Post Helpful? 0
  • +
  • -

#11 NeoTifa   User is offline

  • NeoTifa Codebreaker, the Scourge of Devtester
  • member icon





Reputation: 4681
  • View blog
  • Posts: 19,530
  • Joined: 24-September 08

Re: Java Applet

Posted 14 July 2009 - 06:30 PM

I don't have kids. I'm 19 :(
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1