Difference between Japplet and applet?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 3495 Views - Last Post: 13 February 2010 - 09:38 AM Rate Topic: -----

#1 sly  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 134
  • Joined: 05-December 08

Difference between Japplet and applet?

Posted 07 January 2009 - 09:54 PM

whats the difference between Japplet and applet? and how can i set up a J applet onto a html browser?
Is This A Good Question/Topic? 0
  • +

Replies To: Difference between Japplet and applet?

#2 pbl  Icon User is offline

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

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Difference between Japplet and applet?

Posted 07 January 2009 - 10:13 PM

View Postsly, on 7 Jan, 2009 - 08:54 PM, said:

whats the difference between Japplet and applet? and how can i set up a J applet onto a html browser?

To make the story short...
First version of Java came with AWT which has Label, Applet, Button, RadioButon, ....
Then they figured out that the design/architecture was not perfect or missed some fine tuning so they came up with Swing which has JLabel, JApplet, JButton, JRadioButton,... (almost a J something for all old AWT stuff)

5 years ago, for performance reasons, you had to wonder if you should use AWT or Swing (Swing had a better architecture but some performance drawbacks). This has been fixed since years.
So now, I would personaly state that any new development should be done with Swing unless you have a really good reason like your friend in the middle of the Amazonian jungle who wants to see your Applet and who's browser is still at JRE 1.2

Must of the time, Swing components, share a lot of stuff with their AWT ancestors
The important stuff is not to mix both types of components in the same application... can be tricky with thread stuff

If you look at Layout, ButtonGroup.. they are still AWT stuff there is not such things as JLayout or JButtonGroup

As far as JApplet (or Applet) in an HTML browser you can Google for examples... must be millions of them or search this forum the question has been asked many times and many posts relate to "problems" with them... the final post should show you the examples without bugs
Was This Post Helpful? 2

#3 sly  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 134
  • Joined: 05-December 08

Re: Difference between Japplet and applet?

Posted 07 January 2009 - 11:08 PM

I just dont know how to put it in my html file... It gives a blank frame when i open it here are the codes:



 import java.awt.*;
import java.io.*;
import java.util.Random;
import java.awt.event.*;
import javax.swing.*;

public class game extends JApplet
{
	private KeyboardPanel keyboardPanel = new KeyboardPanel();
	public static void main(String args[])
	{
			
		JFrame frame = new JFrame();
		test applet = new test();
		frame.getContentPane().add(applet, BorderLayout.CENTER);
		applet.init();applet.start();
		frame.setSize(640,480);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);		
		applet.focus();
	}
	public void init()
	{	
		getContentPane().add(keyboardPanel);
		focus();
	}
	public void focus()
	{
		keyboardPanel.requestFocus();
	}
}

class KeyboardPanel extends JPanel implements KeyListener
{
	gameActions ga=new gameActions();
	//double buffering stuff
	Image pix, buffer;
	Graphics backg;
	int mouseX, mouseY;
	int aWidth, aHeight;int switcher=-1;
	//end double buffering
	public KeyboardPanel()
	{
		addKeyListener(this);
	}
	public void init()
	{
		aWidth = getSize().width;	//applet's Width
		aHeight = getSize().height;  //applet's Height
		buffer = createImage(aWidth,aHeight);  //same size as the applet
		backg = buffer.getGraphics();   //copy the image
		backg.setColor(Color.white);
	}	
	public void keyReleased(KeyEvent e)
	{
		switch (e.getKeyCode())
		{
			case KeyEvent.VK_DOWN:
			ga.keyPressed=false;
			break;
			case KeyEvent.VK_UP:
			ga.keyPressed=false;
			break;
			case KeyEvent.VK_RIGHT:
			ga.keyPressed=false;
			break;
			case KeyEvent.VK_LEFT:
			ga.keyPressed=false;
			break;
		}
	}
	public void keyTyped(KeyEvent e)
	{
		
	}
	public void keyPressed(KeyEvent e)
	{
		switch (e.getKeyCode())
		{
			case KeyEvent.VK_DOWN:
			if(!ga.keyPressed){ga.downPressed=true;ga.keyPressed=true;}
			break;
			case KeyEvent.VK_UP:
			if(!ga.keyPressed){ga.upPressed=true;ga.keyPressed=true;}
			break;
			case KeyEvent.VK_RIGHT:
			if(!ga.keyPressed){ga.rightPressed=true;ga.keyPressed=true;}
			break;
			case KeyEvent.VK_LEFT:
			if(!ga.keyPressed){ga.leftPressed=true;ga.keyPressed=true;}
			break;
		}
	}
	public void paint(Graphics g)
	{
		if(ga.first)
		{
			ga.makeMap();
			ga.loadTown(g);
			ga.first=false;
		}
		if(!ga.battle)
		{
			ga.mapLvl1(g);		
			//men movement
			if(ga.downPressed)
			{ga.moveDown(g);}
			else if(ga.upPressed)
			{ga.moveUp(g);}
			else if(ga.rightPressed)
			{ga.moveRight(g);}
			else if(ga.leftPressed)
			{ga.moveLeft(g);}
			else
			{ga.drawStand(g);}
			//end men movement, begin battle check
			ga.checkBattle();
			//end battle check
		}
		else if(ga.battle)
		{
			ga.battleIdle(g);
		}
		repaint();
	}
} 


and the html:

 <html>
<head><title>game</title></head>
<body>
<applet
codebase = "."
code = "game.class"
name = "game"
width = "640"
height = "480"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>
</body>
</html> 

Was This Post Helpful? 0
  • +
  • -

#4 ayman_mastermind  Icon User is offline

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

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

Re: Difference between Japplet and applet?

Posted 07 January 2009 - 11:19 PM

@sly, your html code seems to be correct and i tried it on another class and it worked. But The current class that you showed is insufficient since it wont compile, please also show the gameActions class so that i can test the whole program on my machine :)
Was This Post Helpful? 0
  • +
  • -

#5 sly  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 134
  • Joined: 05-December 08

Re: Difference between Japplet and applet?

Posted 08 January 2009 - 03:54 AM

  import java.awt.*;
import java.io.*;
import java.util.Random;
import java.awt.event.*;
import javax.swing.*;

class gameActions
{
	int charX=25;int charY=25;
	boolean keyPressed, leftPressed, rightPressed, upPressed, downPressed=false;
	boolean first=true;//tells when to create the map
	boolean battle=false;
	final int down=1, up=2, left=3, right=4;
	int direction=1;
	int walkSwitch, sideSwitch=1;
	int array1[][]=new int[50][24];
	int array2[][]=new int[50][24];
	int maxX=680;int minX=40;
	int maxY=480;int minY=0;
	int steps=10;
	Image grass=Toolkit.getDefaultToolkit().createImage("tiles/grass.jpg");
	Image road1=Toolkit.getDefaultToolkit().createImage("tiles/road.jpg");
	Image road2=Toolkit.getDefaultToolkit().createImage("tiles/road4way.jpg");
	Image road3=Toolkit.getDefaultToolkit().createImage("tiles/roadHorr.jpg");
	Image manDownC=Toolkit.getDefaultToolkit().createImage("manTown/down/M.gif");
	Image manDownL=Toolkit.getDefaultToolkit().createImage("manTown/down/L.gif");
	Image manDownR=Toolkit.getDefaultToolkit().createImage("manTown/down/R.gif");	
	Image manUpC=Toolkit.getDefaultToolkit().createImage("manTown/up/M.gif");	
	Image manUpL=Toolkit.getDefaultToolkit().createImage("manTown/up/L.gif");
	Image manUpR=Toolkit.getDefaultToolkit().createImage("manTown/up/R.gif");	
	Image manLeftC=Toolkit.getDefaultToolkit().createImage("manTown/left/M.gif");	
	Image manLeftL=Toolkit.getDefaultToolkit().createImage("manTown/left/L.gif");
	Image manLeftR=Toolkit.getDefaultToolkit().createImage("manTown/left/R.gif");	
	Image manRightC=Toolkit.getDefaultToolkit().createImage("manTown/right/M.gif");	
	Image manRightL=Toolkit.getDefaultToolkit().createImage("manTown/right/L.gif");
	Image manRightR=Toolkit.getDefaultToolkit().createImage("manTown/right/R.gif");	
	Image manBattleC=Toolkit.getDefaultToolkit().createImage("manTown/fighterNormMiddle.gif");
	Image flameFlan=Toolkit.getDefaultToolkit().createImage("monsters/flameFlan.gif");
	Image thunderFlan=Toolkit.getDefaultToolkit().createImage("monsters/thunderFlan.gif");
	Image waterFlan=Toolkit.getDefaultToolkit().createImage("monsters/waterFlan.gif");
	Image iceFlan=Toolkit.getDefaultToolkit().createImage("monsters/iceFlan.gif");
	Random r=new Random();
	monster m1=new monster();
	monster m2=new monster();
	monster m3=new monster();
	public void sleep(int x)
	{
		int c=0;
		for(int z=10000*x;c<z;c++)
		{}
	}
	public void loadTown(Graphics g)
	{
		g.drawImage(grass, 0,0,null);g.drawImage(road1, 0,0,null);g.drawImage(road2, 0,0,null);g.drawImage(road3, 0,0,null);sleep(5);
		g.drawImage(manDownC, 0,0,null);g.drawImage(manUpC, 0,0,null);g.drawImage(manLeftC, 0,0,null);g.drawImage(manRightC, 0,0,null);sleep(5);
		g.drawImage(manDownL, 0,0,null);g.drawImage(manUpL, 0,0,null);g.drawImage(manLeftL, 0,0,null);g.drawImage(manRightL, 0,0,null);sleep(5);
		g.drawImage(manDownR, 0,0,null);g.drawImage(manUpR, 0,0,null);g.drawImage(manLeftR, 0,0,null);g.drawImage(manRightR, 0,0,null);sleep(5);
		g.setColor(Color.black);
		g.fillRect(0,0,500,500);
		sleep(500);
		
	}
	public void moveDown(Graphics g)
	{
		charY++;walkSwitch++;direction=down;
		if(walkSwitch>0&&walkSwitch<=20)
		{	if(sideSwitch==1){g.drawImage(manDownL,charX,charY,null);}
			else if(sideSwitch==2){g.drawImage(manDownR,charX,charY,null);}	}
		else if(walkSwitch>20&&walkSwitch<=25)
		{	g.drawImage(manDownC,charX,charY,null);
			if(walkSwitch==25){keyPressed=false;downPressed=false;walkSwitch=0;steps--;}
			if(sideSwitch==1){sideSwitch=2;}
			else if(sideSwitch==2){sideSwitch=1;}	}		
	}
	public void moveUp(Graphics g)
	{
		charY--;walkSwitch++;direction=up;
		if(walkSwitch>0&&walkSwitch<=20)
		{	if(sideSwitch==1){g.drawImage(manUpL,charX,charY,null);}
			else if(sideSwitch==2){g.drawImage(manUpR,charX,charY,null);}	}
		else if(walkSwitch>20&&walkSwitch<=25)
		{	g.drawImage(manUpC,charX,charY,null);
			if(walkSwitch==25){keyPressed=false;upPressed=false;walkSwitch=0;steps--;}
			if(sideSwitch==1){sideSwitch=2;}
			else if(sideSwitch==2){sideSwitch=1;}	}
	}
	public void moveLeft(Graphics g)
	{
		walkSwitch++;charX--;direction=left;
		if(walkSwitch>0&&walkSwitch<=20)
		{	if(sideSwitch==1){g.drawImage(manLeftL,charX,charY,null);}
			else if(sideSwitch==2){g.drawImage(manLeftR,charX,charY,null);}	}
		else if(walkSwitch>20&&walkSwitch<=25)
		{	g.drawImage(manLeftC,charX,charY,null);
			if(walkSwitch==20){keyPressed=false;leftPressed=false;walkSwitch=0;steps--;}	
			if(sideSwitch==1){sideSwitch=2;}
			else if(sideSwitch==2){sideSwitch=1;}	}
		
	}
	public void moveRight(Graphics g)
	{
		charX++;walkSwitch++;direction=right;
		if(walkSwitch>0&&walkSwitch<=15)
		{	if(sideSwitch==1){g.drawImage(manRightL,charX,charY,null);}
			else if(sideSwitch==2){g.drawImage(manRightR,charX,charY,null);}	}
		else if(walkSwitch>15&&walkSwitch<=20)
		{	g.drawImage(manRightC,charX,charY,null);
			if(walkSwitch==20){keyPressed=false;rightPressed=false;walkSwitch=0;steps--;}	
			if(sideSwitch==1){sideSwitch=2;}
			else if(sideSwitch==2){sideSwitch=1;}	}
	}
	public void drawStand(Graphics g)
	{
		if(direction==down)
		{
			g.drawImage(manDownC,charX,charY,null);
		}
		else if(direction==up)
		{
			g.drawImage(manUpC,charX,charY,null);
		}
		else if(direction==left)
		{
			g.drawImage(manLeftC,charX,charY,null);
		}
		else if(direction==right)
		{
			g.drawImage(manRightC,charX,charY,null);
		}
	}
	public void makeMap()
	{
		for(int x=0;x<50;x++)
		{
			for(int y=0;y<24;y++)
			{
				array1[x][y]=0;
			}
		}
		for(int x=0;x<24;x++)
		{
			array1[9][x]=1;
		}
		for(int x=0;x<50;x++)
		{
			array1[x][9]=3;
		}
		array1[9][9]=2;
		array2[3][3]=1;
	}
	public void mapLvl1(Graphics g)
	{
		for(int x=0;x<640;x+=20)
		{
			for(int y=0;y<480;y+=20)
			{
				if(array1[x/20][y/20]==0)
				{g.drawImage(grass,x,y,null);}
				else if(array1[x/20][y/20]==1)
				{g.drawImage(road1,x,y,null);}
				else if(array1[x/20][y/20]==2)
				{g.drawImage(road2,x,y,null);}
				else if(array1[x/20][y/20]==3)
				{g.drawImage(road3,x,y,null);}
			}
		}
	}
	public void mapLvl2(Graphics g)
	{
		for(int x=0;x<250;x+=25)
		{
			for(int y=0;y<250;y+=25)
			{
				if(array2[x/25][y/25]==1)
				{}
			}
		}
	}
	public void checkBattle()
	{
		if(steps==0)
		{
			steps=r.nextInt(30)+10;callBattle();
		}
	}
	public void callBattle()
	{
		m1.create();
		try		{ Thread.sleep(500);}
		catch(InterruptedException e)	{}
		m2.create();
		try	  { Thread.sleep(500);}
		catch(InterruptedException e)	{}
		m3.create();
		battle=true;
	}
	public void battleIdle(Graphics g)
	{
		g.setColor(Color.blue);
		g.fillRect(0,0,500,500);
		g.setColor(Color.green);
		g.fillRect(0,100,500,400);
		g.drawImage(manBattleC,20,300,null);
		switch(m1.number)
		{
			case 0:	g.drawImage(flameFlan,300,200,null);	break;
			case 1:	g.drawImage(iceFlan,300,200,null);		break;
			case 2:	g.drawImage(waterFlan,300,200,null);	break;
			case 3:	g.drawImage(thunderFlan,300,200,null);	break;
			case 4:	//g.drawImage(flameFlan,300,200,null);	break;
		}
		switch(m2.number)
		{
			case 0:	g.drawImage(flameFlan,300,300,null);	break;
			case 1:	g.drawImage(iceFlan,300,300,null);		break;
			case 2:	g.drawImage(waterFlan,300,300,null);	break;
			case 3:	g.drawImage(thunderFlan,300,300,null);	break;
			case 4:	//g.drawImage(flameFlan,300,300,null);	break;
		}	
		switch(m3.number)
		{
			case 0:	g.drawImage(flameFlan,300,400,null);	break;
			case 1:	g.drawImage(iceFlan,300,400,null);		break;
			case 2:	g.drawImage(waterFlan,300,400,null);	break;
			case 3:	g.drawImage(thunderFlan,300,400,null);	break;
			case 4:	//g.drawImage(flameFlan,300,400,null);	break;
		}	
	}
	public void attChoice1()
	{
		
	}
	public void monChoice1()
	{
		
	}
	public void specailChoice1()
	{
		
	}
	public void itemChoice1()
	{
		
	}
	public void escapeChoice1()
	{
		
	}
}  

Was This Post Helpful? 0
  • +
  • -

#6 ayman_mastermind  Icon User is offline

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

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

Re: Difference between Japplet and applet?

Posted 08 January 2009 - 06:27 AM

I couldn't run your code since the monster class is missing, i have to test your program in order to figure out what is causing the problem, by taking looking at the code, i think the problem MAY be due to white background that you have set for the applet. If i where you i would change the background color
 backg.setColor(Color.white);

to another color for instance, red or black and load the page if the background of the applet appears to be red then the problem was surely from the background code of the applet, since the page also has a white background which makes it appear displaying nothing. If everything stayed the same then the problem is because another thing... this is just an assumption, as i did not thoroughly study your code, just try it... and if it does not work try to show the monster class so that i can test the program on my machine... i hope this helps, good luck ;)

This post has been edited by ayman_mastermind: 08 January 2009 - 06:29 AM

Was This Post Helpful? 0
  • +
  • -

#7 sly  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 134
  • Joined: 05-December 08

Re: Difference between Japplet and applet?

Posted 08 January 2009 - 01:04 PM

That wont do anything, My problem is that the applet isnt even running... it says: Error Click for details when i open game.html...

and on the bottom of the page were it usually says done it says: Applet game notinited.

heres my monster.java

 import java.awt.*;
import java.io.*;
import java.util.Random;
import java.awt.event.*;
import javax.swing.*;

public class monster
{
	String name;
	int hp, attack, def, mAttack, mDef, eva, number;
	final int fire=0; final int water=1;final int thunder=2;final int ice=3;
	final int dark=4; final int holy=5;final int sword=6;
	boolean weak[]= new boolean[7];
	boolean strong[]= new boolean[7];
	public void create()
	{
		Random r=new Random();
		switch(r.nextInt(5))
		{
			case 0:
			number=0;
			name="flame flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[ice]=true;weak[dark]=true;
			strong[fire]=true;
			break;
			case 1:
			number=1;
			name="ice flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[fire]=true;weak[dark]=true;
			strong[ice]=true;
			break;
			case 2:
			number=2;
			name="water flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[thunder]=true;weak[dark]=true;
			strong[water]=true;
			break;
			case 3:
			number=3;
			name="thunder flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[water]=true;weak[dark]=true;
			strong[thunder]=true;break;
			case 4:
			number=4;
			name="goblin";System.out.print(name);
			hp=75;attack=35;def=20;mAttack=10;mDef=10;eva=6;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[dark]=true;
			break;
		}
	}
}  

Was This Post Helpful? 0
  • +
  • -

#8 sly  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 134
  • Joined: 05-December 08

Re: Difference between Japplet and applet?

Posted 08 January 2009 - 06:13 PM

anyone know what my problem is?
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

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

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Difference between Japplet and applet?

Posted 08 January 2009 - 06:47 PM

View Postsly, on 8 Jan, 2009 - 05:13 PM, said:

anyone know what my problem is?

And where is your test class ?
Was This Post Helpful? 0
  • +
  • -

#10 sly  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 134
  • Joined: 05-December 08

Re: Difference between Japplet and applet?

Posted 08 January 2009 - 06:53 PM

ok here is my test.class and keyboardpanel.class these are the last ones...
i uploaded them ti uppit

test.class
http://uppit.com/26QTUZ

keyboardpanel.class
http://uppit.com/GIQRZG
Was This Post Helpful? 0
  • +
  • -

#11 sly  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 134
  • Joined: 05-December 08

Re: Difference between Japplet and applet?

Posted 08 January 2009 - 09:48 PM

anyone?
Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

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

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Difference between Japplet and applet?

Posted 08 January 2009 - 10:17 PM

View Postsly, on 8 Jan, 2009 - 08:48 PM, said:

anyone?

Your URL does not work
BTW this site has been attacked before by hackers asking to dowload/goseethere posts
so... post your code the regular way or forget about it
Post your code
:code:

This post has been edited by pbl: 08 January 2009 - 10:46 PM

Was This Post Helpful? 0
  • +
  • -

#13 dziants  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-January 09

Re: Difference between Japplet and applet?

Posted 21 January 2009 - 08:22 AM

I was looking for a similar solution as am upgrading an old applet, and came across your question.

As no one has yet answered this properly here, I will document what I did:

1) Implement your applet with KeyEventDispatcher interface.
public class SnakeApplet extends JApplet implements java.awt.KeyEventDispatcher {


2) The compiler will insist that you implement method:
public boolean dispatchKeyEvent(java.awt.event.KeyEvent evt)

There you put your processing on the key events.

3) The dispatcher has to be registered with the KeyboardFocusManager
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);

which would normally be done in the applet init() method.
In our case the applet is the dispatcher so use "this".

This solution takes into account the JFC changes from Java 1.4 and up. Hope this helps. I might be posting this solution on other sites which I came across.

View Postsly, on 8 Jan, 2009 - 12:04 PM, said:

That wont do anything, My problem is that the applet isnt even running... it says: Error Click for details when i open game.html...

and on the bottom of the page were it usually says done it says: Applet game notinited.

heres my monster.java

 import java.awt.*;
import java.io.*;
import java.util.Random;
import java.awt.event.*;
import javax.swing.*;

public class monster
{
	String name;
	int hp, attack, def, mAttack, mDef, eva, number;
	final int fire=0; final int water=1;final int thunder=2;final int ice=3;
	final int dark=4; final int holy=5;final int sword=6;
	boolean weak[]= new boolean[7];
	boolean strong[]= new boolean[7];
	public void create()
	{
		Random r=new Random();
		switch(r.nextInt(5))
		{
			case 0:
			number=0;
			name="flame flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[ice]=true;weak[dark]=true;
			strong[fire]=true;
			break;
			case 1:
			number=1;
			name="ice flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[fire]=true;weak[dark]=true;
			strong[ice]=true;
			break;
			case 2:
			number=2;
			name="water flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[thunder]=true;weak[dark]=true;
			strong[water]=true;
			break;
			case 3:
			number=3;
			name="thunder flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[water]=true;weak[dark]=true;
			strong[thunder]=true;break;
			case 4:
			number=4;
			name="goblin";System.out.print(name);
			hp=75;attack=35;def=20;mAttack=10;mDef=10;eva=6;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[dark]=true;
			break;
		}
	}
}  

Was This Post Helpful? 0
  • +
  • -

#14 forU  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-January 09

Re: Difference between Japplet and applet?

Posted 23 January 2009 - 08:05 AM

Make sure your JFrame is set up correctly and also shown Example of a Jframe in a class with nothing added to the fream
import java.awt.*;

import javax.swing.*;

public class Game extends JApplet
{
	public void init()
	{
		final JFrame frame = new JFrame();
		frame.setSize(640,480);
		frame.setBackground(Color.BLUE);
		frame.validate();
		frame.setSize(800,650);
		frame.setVisible(true);
		frame.show();
		add(frame);

	}
}


Also you don't need the "codebase" tag in your html page

Hope that helps


View Postdziants, on 21 Jan, 2009 - 07:22 AM, said:

I was looking for a similar solution as am upgrading an old applet, and came across your question.

As no one has yet answered this properly here, I will document what I did:

1) Implement your applet with KeyEventDispatcher interface.
public class SnakeApplet extends JApplet implements java.awt.KeyEventDispatcher {


2) The compiler will insist that you implement method:
public boolean dispatchKeyEvent(java.awt.event.KeyEvent evt)

There you put your processing on the key events.

3) The dispatcher has to be registered with the KeyboardFocusManager
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);

which would normally be done in the applet init() method.
In our case the applet is the dispatcher so use "this".

This solution takes into account the JFC changes from Java 1.4 and up. Hope this helps. I might be posting this solution on other sites which I came across.

View Postsly, on 8 Jan, 2009 - 12:04 PM, said:

That wont do anything, My problem is that the applet isnt even running... it says: Error Click for details when i open game.html...

and on the bottom of the page were it usually says done it says: Applet game notinited.

heres my monster.java

 import java.awt.*;
import java.io.*;
import java.util.Random;
import java.awt.event.*;
import javax.swing.*;

public class monster
{
	String name;
	int hp, attack, def, mAttack, mDef, eva, number;
	final int fire=0; final int water=1;final int thunder=2;final int ice=3;
	final int dark=4; final int holy=5;final int sword=6;
	boolean weak[]= new boolean[7];
	boolean strong[]= new boolean[7];
	public void create()
	{
		Random r=new Random();
		switch(r.nextInt(5))
		{
			case 0:
			number=0;
			name="flame flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[ice]=true;weak[dark]=true;
			strong[fire]=true;
			break;
			case 1:
			number=1;
			name="ice flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[fire]=true;weak[dark]=true;
			strong[ice]=true;
			break;
			case 2:
			number=2;
			name="water flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[thunder]=true;weak[dark]=true;
			strong[water]=true;
			break;
			case 3:
			number=3;
			name="thunder flan";System.out.print(name);
			hp=50;attack=5;def=40;mAttack=40;mDef=10;eva=5;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[water]=true;weak[dark]=true;
			strong[thunder]=true;break;
			case 4:
			number=4;
			name="goblin";System.out.print(name);
			hp=75;attack=35;def=20;mAttack=10;mDef=10;eva=6;
			for(int x=0;x<7;x++)
			{weak[x]=false;strong[x]=false;}
			weak[dark]=true;
			break;
		}
	}
}  

Was This Post Helpful? 0
  • +
  • -

#15 Cruncher  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-February 10

Re: Difference between Japplet and applet?

Posted 13 February 2010 - 08:53 AM

Am i the only one that noticed that he has a main method for an applet?

lol.. the main method only goes in an application, for applets "init" would be the equivilent.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2