Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to make Applet in NetBeans?  (Read 10075 times)
0 Members and 1 Guest are viewing this topic.
Offline Archibald

Junior Member


Projects: 1



« Posted 2012-02-18 14:43:08 »

I need to create applet for Java4kb competition. Basicly, what should I click in NetBeans IDE to make one of these templates "compile" (I'm getting "can't find main()")?
http://www.java-gaming.org/topics/applet-templates/21626/view.html

And yes, I was unable to google it, which is kind of strange since something that basic should be covered somewhere...
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-02-19 04:31:51 »

Applets don't have main methods. Netbeans should automatically run your applet in the AppletViewer when you hit the run button. What problems did you encounter?

Offline Archibald

Junior Member


Projects: 1



« Reply #2 - Posted 2012-02-19 10:59:53 »

NetBeans 7.1

Let's say I want to run this simple HelloWorld code from wikipedia:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
import java.applet.Applet;
import java.awt.*;
 
// Applet code for the "Hello, world!" example.
// This should be saved in a file named as "HelloWorld.java".
public class HelloWorld extends Applet {
  // This method is mandatory, but can be empty (i.e., have no actual code).
 public void init() { }
 
  // This method is mandatory, but can be empty.(i.e.,have no actual code).
 public void stop() { }
 
  // Print a message on the screen (x=20, y=10).
 public void paint(Graphics g) {
    g.drawString("Hello, world!", 20,10);
 
  // Draws a circle on the screen (x=40, y=30).
   g.drawArc(40,30,20,20,0,360);
  }
}


I click:
- NewProject/Java/JavaApplication
- Set project name to: "AppletHelloWorld", Finish
- click on AppletHelloWorld.java, I see this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package applethelloworld;

/**
 *
 * @author Admin
 */

public class AppletHelloWorld {

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) {
   // TODO code application logic here
   }
}

- I copy/past the code and change "public class HelloWorld extends Applet" to "public class AppletHelloWorld extends Applet"
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
import java.applet.Applet;
import java.awt.*;
 
// Applet code for the "Hello, world!" example.
// This should be saved in a file named as "HelloWorld.java".
public class AppletHelloWorld extends Applet {
  // This method is mandatory, but can be empty (i.e., have no actual code).
 public void init() { }
 
  // This method is mandatory, but can be empty.(i.e.,have no actual code).
 public void stop() { }
 
  // Print a message on the screen (x=20, y=10).
 public void paint(Graphics g) {
    g.drawString("Hello, world!", 20,10);
 
  // Draws a circle on the screen (x=40, y=30).
   g.drawArc(40,30,20,20,0,360);
  }
}

- click Run, "BUILD SUCCESSFUL (total time: 0 seconds)", nothing appears on the screen
- Click "Clean and Build Main Project", click Run again, get an error "applethelloworld.AppletHelloWorld class wasn't found in AppletHelloWorld project; select the main class".

I guess, I clicked something wrong along the way Smiley
I was checking several tutorials but I always stumbled on some differences (like there is no "Run as Applet" option in NetBeans  7.1 or the option they select in the tutorial does not exist)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Danny02
« Reply #3 - Posted 2012-02-19 11:58:01 »

you can go to the project properties
Application->Web Start
-Enable Web Start
-Applet descriptor


I do it a bit different I create a Component like a Canvas which I can attach to an applet or jframe, depending on how I build it(desktop or applet)
Offline Archibald

Junior Member


Projects: 1



« Reply #4 - Posted 2012-02-19 12:03:18 »

you can go to the project properties
Application->Web Start
-Enable Web Start
-Applet descriptor
No change, still "class not found". Also I'm getting now an icon "AppletHelloWorld needs to be compiled", no matter what I click I can't make it disappear.
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-02-19 15:01:54 »

I just opened up Netbeans, wrote a little test applet, and wow I'm getting the same error: "Main class not found."

Another reason why Eclipse > Netbeans (please let's not start an IDE war....) Grin

Offline Archibald

Junior Member


Projects: 1



« Reply #6 - Posted 2012-02-20 15:47:15 »

In Eclipse it works like a charm... And I was already so used to the faster launch speed of NetBeans Sad
Offline Danny02
« Reply #7 - Posted 2012-02-20 16:09:40 »

you just have to hit SHIFT+F6(run file) while being in your applet class file in netbeans

Offline 12bob50

Junior Newbie





« Reply #8 - Posted 2012-02-20 16:23:02 »

Google Chrome's Java installation messes up netbeans applets.
Offline Danny02
« Reply #9 - Posted 2012-02-20 16:42:36 »

google chromes java? - what could you possible do with an applet so that it have browser specific behavior
netbeans applets? - why do you think so? what settings
messes up? - what happens?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 12bob50

Junior Newbie





« Reply #10 - Posted 2012-02-20 16:49:28 »

I made a simple hello world applet in netbeans, didnt work, uninstalled google chrome's java, recompiled and ran, worked perfectly.
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2012-02-20 19:31:25 »

There is no such thing as "Google Chrome's Java". There is only 1 Java installation.

Offline 12bob50

Junior Newbie





« Reply #12 - Posted 2012-02-20 20:56:12 »

Chrome has its own java installation for their browser.
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #13 - Posted 2012-02-20 21:02:51 »

You mean that "chromeinstall.exe" file that you click? All that does is download the JRE for system-wide use.....

Offline 12bob50

Junior Newbie





« Reply #14 - Posted 2012-02-20 21:22:03 »

It still breaks applets when you use netbeans
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #15 - Posted 2012-02-20 21:50:38 »

Well I blame Netbeans Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (12 views)
2014-09-01 06:59:12

TehJavaDev (23 views)
2014-08-29 02:26:30

CopyableCougar4 (27 views)
2014-08-23 03:31:30

atombrot (40 views)
2014-08-19 17:29:53

Tekkerue (38 views)
2014-08-16 14:45:27

Tekkerue (34 views)
2014-08-16 14:22:17

Tekkerue (24 views)
2014-08-16 14:20:21

Tekkerue (34 views)
2014-08-16 14:12:11

Rayexar (72 views)
2014-08-11 10:49:23

BurntPizza (47 views)
2014-08-10 05:09:32
List of Learning Resources
by Longor1996
2014-08-16 18:40:00

List of Learning Resources
by SilverTiger
2014-08-06 03:33:27

Resources for WIP games
by CogWheelz
2014-08-02 00:20:17

Resources for WIP games
by CogWheelz
2014-08-02 00:19:50

List of Learning Resources
by SilverTiger
2014-08-01 00:29:50

List of Learning Resources
by SilverTiger
2014-08-01 00:26:06

List of Learning Resources
by SilverTiger
2014-07-31 19:54:12

HotSpot Options
by dleskov
2014-07-08 09:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!