Error when loading applet.

APPLET tag missing CODE parameter.

Page 1 of 1

9 Replies - 2482 Views - Last Post: 22 February 2009 - 02:58 PM Rate Topic: -----

#1 bear(NP)  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 144
  • Joined: 18-February 09

Error when loading applet.

Posted 21 February 2009 - 05:23 AM

Hey guys I get an

Quote

APPLET tag missing CODE parameter.
error when I try to run a simple game that just moves a ball when the 'd' key is pressed.
Here's the HTML file, which works with simpler apps (by only changing the class name):
<HTML>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET>
	code	= "FirstGame.class"
	width	= "500"
	height	= "500"
</APPLET>
</CENTER>
</BODY>
</HTML>



and here's the basic game: (not mine, tutorials used included)
//http://oneslime.net/java/Tutorial_3
//http://www.dreamincode.net/forums/showtopic14233.htm
//http://www.cs.miami.edu/~duncan/spring06/csc329/basicJava/Pong.java
import java.applet.*;
import java.applet.Applet;
import javax.swing.*;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class FirstGame extends JApplet implements KeyListener, Runnable{
	public int x_pos = 10, y_pos = 100, radius = 20;
	Graphics g;
	public void init(){
	}
	public void start(){
		//creates new thread
		Thread th = new Thread (this);
		//starts thread
		th.start();
	}
	public void stop(){
	}
	public void destroy(){
	}
	public void run(){
		//lowers thread priority (why?)
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
		while(true){
			repaint();
			}	
		}
	public void paint(Graphics g){
		//sets color
		g.setColor(Color.red);
		//creates a filled circle
		g.fillOval(x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);
	}
	public void keyPressed(KeyEvent e) {
		char c = e.getKeyChar();
		switch (c){
			case 'd':
			case 'D':
			x_pos += 5;
		}
	}
		public void keyReleased(KeyEvent e) {
	}
		public void keyTyped(KeyEvent e) {
			char c = e.getKeyChar();
			switch (c){
				case 'd':
				case 'D':
				x_pos += 5;
			}
	}
}



can anybody help?

Is This A Good Question/Topic? 0
  • +

Replies To: Error when loading applet.

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: Error when loading applet.

Posted 21 February 2009 - 05:32 AM

you need to add a KeyListner, e.g.
	public void init(){
	this.addKeyListener(this);

	}


Was This Post Helpful? 0
  • +
  • -

#3 bear(NP)  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 144
  • Joined: 18-February 09

Re: Error when loading applet.

Posted 21 February 2009 - 06:01 AM

That may have worked, i have no idea :'(
the problem is it shows a black screen with a white box, and in the white box there's a smaller yellow box that says "JAVA" with the coffee mug and a loading bar underneath... and that loading bar never loads... :'(
EDIT: I'm still getting the same error... :'(

This post has been edited by bear(NP): 21 February 2009 - 06:03 AM

Was This Post Helpful? 0
  • +
  • -

#4 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: Error when loading applet.

Posted 21 February 2009 - 06:15 AM

View Postbear(NP), on 21 Feb, 2009 - 12:01 PM, said:

That may have worked, i have no idea :'(
the problem is it shows a black screen with a white box, and in the white box there's a smaller yellow box that says "JAVA" with the coffee mug and a loading bar underneath... and that loading bar never loads... :'(
EDIT: I'm still getting the same error... :'(

it works OK for me - a red circle appears which changes size when I hit d on the keyboard

have you tried running it with the AppletViewer and well as web browser?
Was This Post Helpful? 0
  • +
  • -

#5 bear(NP)  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 144
  • Joined: 18-February 09

Re: Error when loading applet.

Posted 21 February 2009 - 06:55 AM

I have no idea what the appletviewer is, let alone how to use it :( i'm sorry i just started programing a month ago :(

i just updated to the jdk and jre 6u12 from jdk 6u10 and jre6u7 (but i can't seem to find the docs for jdk 6u12) would that help for any reason?
Was This Post Helpful? 0
  • +
  • -

#6 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: Error when loading applet.

Posted 21 February 2009 - 07:36 AM

View Postbear(NP), on 21 Feb, 2009 - 12:55 PM, said:

I have no idea what the appletviewer is, let alone how to use it :( i'm sorry i just started programing a month ago :(

i just updated to the jdk and jre 6u12 from jdk 6u10 and jre6u7 (but i can't seem to find the docs for jdk 6u12) would that help for any reason?

you run the AppletViewer by opening a Command Prompt changing to the directory where the java & html files are and typing
AppletViewer FirstGame.html

upgrading should make no real difference - what machine & operating system are you using?
Was This Post Helpful? 0
  • +
  • -

#7 bear(NP)  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 144
  • Joined: 18-February 09

Re: Error when loading applet.

Posted 21 February 2009 - 09:18 PM

Alright, but will changing the jdk and the jre to the same version do anything?
Windows XP (death to vista) SP: 3; Intel Pent. M Proces. 1.60 GHz, 512mb ram, ATI mobility Radeon 7500

EDIT: i got this error when i typed that into C. prompt: 'Appletviewer' is not recognized by an internal or external command, operable program, or batch file.

This post has been edited by bear(NP): 21 February 2009 - 09:31 PM

Was This Post Helpful? 0
  • +
  • -

#8 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: Error when loading applet.

Posted 22 February 2009 - 12:08 AM

View Postbear(NP), on 22 Feb, 2009 - 03:18 AM, said:

Alright, but will changing the jdk and the jre to the same version do anything?
Windows XP (death to vista) SP: 3; Intel Pent. M Proces. 1.60 GHz, 512mb ram, ATI mobility Radeon 7500

EDIT: i got this error when i typed that into C. prompt: 'Appletviewer' is not recognized by an internal or external command, operable program, or batch file.

the updates to the jdk add new APIs and fix any errors

to run applet viewer try typing
"C:\Program Files\Java\jdk1.6.0_12\bin\AppletViewer" FirstGame.htm
Was This Post Helpful? 1
  • +
  • -

#9 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: Error when loading applet.

Posted 22 February 2009 - 04:43 AM

Quote

That may have worked, i have no idea :'(
the problem is it shows a black screen with a white box, and in the white box there's a smaller yellow box that says "JAVA" with the coffee mug and a loading bar underneath... and that loading bar never loads... :'(
EDIT: I'm still getting the same error... :'(

It also showed like this when i ran your Java and html code too, your Java code is not wrong but your HTML code is, your HTML code for the applet is wrong it has to be like this:
<HTML>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET
	code	= "FirstGame.class"
	width	= "500"
	height	= "500">
</applet>
</CENTER>
</BODY>
</HTML>


and not as you have done, this way the applet will load and how the red ball but the red ball wont work in your case because as Horace told you you need to add an action, once the action listener is there, the progra would run correctly along with the corrected HTML code, i hope this helps, good luck ;)
Was This Post Helpful? 1
  • +
  • -

#10 bear(NP)  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 144
  • Joined: 18-February 09

Re: Error when loading applet.

Posted 22 February 2009 - 02:58 PM

action viewer? o boy... :( thanks anyways guys, I'll run with that and see what happens

EDIT: WOOOO!!!! got the updates done!!! (forgot to remove old jre/jdk path in JCreator) woo! it loaded the first time in under a minute!!! when i pressed the d key it chriped at me, but if i get an action listener going like you said that should fix that problem- thank you so much guys!!! WOOO!!!

This post has been edited by bear(NP): 22 February 2009 - 03:27 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1