Hello Members,

I have a java file (myapplet.java), the myapplet.class file and the myapplet.html file. I would like to run this applet on my webpage. I use IE 7.0

The myapplet.html and myapplet.class files are both in the public_html folder of my UNIX account,which happens to be on the school server.

Let's say my webpage is:

www.mycollege.edu/~myself

This is the index.html webpage. On this webpage, I have a link for my applet, whose URL is:

www.mycollege.edu/~myself/myapplet.html

The following is my myapplet.html file:

<APPLET
CODE = myapplet.class
WIDTH = 1000
HEIGHT = 800
>
</APPLET>

When I click on the link that is supposed to run the applet, I get the "ClassDefNotFound Exception."

I would appreciate any help in fixing this problem.

Thanks a lot!!

and don't forget package names, don't forget that classnames (as everything) are case sensitive, don't forget to include external jars required by the applet, etc. etc..

Interesting exception by the way, must be a very weird JVM you have running.

Hello s_sridhar & jwenting,

Thanks a lot for your replies!!

I tried the appletcode base and it still comes up with the same error.

I do not have any packages or .jar files for this program. It is a very simple applet which plays the Hangman game.

Any further suggestions?

Thank you!!
sciprog1

and always put your classes in a package...
Not sure how the plugin handles classes that aren't, but I'd not be surprised if it can cause problems.

Hello Again,

I have done exactly what the link is advising. Following are my files:

Hangman.java:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.Thread;

public class Hangman extends JApplet
{
	private final int MAX_X = 1000, MAX_Y = 750;
	private String subject, word, z, rightLetters[], incorrect;
	private int i, x, y, a[], b[], wrong = 0, right = 0, count3 = 0, flag5 = 0, flag6 = 0, flag7 = 0, k;
	private int flag4 = 0, flag = 0, c[], d[], e[], j, count2 = 0, flag3 = 0, count4 = 0, flag2 = 0, count = 0, x1;
	private JTextField field;
	private JButton button;
	private FlowLayout layout;
	
	public void init ()
	{

		a = new int [50];
		b = new int [50];
		c = new int [50];
		d = new int [50];
		e = new int [50];
		rightLetters = new String [50];
		for (i = 0; i < 50; i++)
		{
			c[i] = 0;
			rightLetters[i] = " ";
		}
		
		layout = new FlowLayout();
    		Container content = getContentPane();
    		content.setLayout(new FlowLayout()); 
		layout.setAlignment(FlowLayout.RIGHT);
		Frame frame = new Frame();
		subject = JOptionPane.showInputDialog("Input the subject");
		word = JOptionPane.showInputDialog("Input the word");
		field = new JTextField(10);
		button = new JButton("Guess a letter!");
		add(field);
		add(button);
		
		button.addActionListener(
			
		new ActionListener(){
			public void actionPerformed(ActionEvent event)
			{
				z = field.getText();
				z.matches("\\D{1}");
				flag = 0;
				
		
				for (i = 0; i < word.length(); i++)
				{
					if (z.matches("\\D{1}") == true)
					{
						if (z.charAt(0) == word.charAt(i))
						{
			
							flag = 1;
							c[i] = 1;
							rightLetters[i] = z;
							
							right++;
							count4 = 0;
							flag6 = 1;
						}
						else if (i == word.length() - 1 && flag == 0)
						{
							wrong++;
							flag = 1;
							if (incorrect == null)
							{
								incorrect = z;
								incorrect += " ";
							}
							else
							{
								for (j = 0; j < incorrect.length(); j++)
								{
									if (incorrect.charAt(j) == z.charAt(0))
									{
										flag2 = 1;
										count2++;
									}
								}
							
								if (flag2 == 0)
								{
									incorrect += z;
									incorrect += " ";
								}
								else
								{
									flag2 = 0;
								}
							}
							if (count2 != 0)
							{
								wrong--;
								count2 = 0;
							}
						}
					}
					else
					{
						flag7 = 1;
					}
					if (flag7 == 1)
					{
						flag7 = 0;
						JOptionPane.showMessageDialog(null, "Please only enter 1 letter at a time, and NO numbers please.", "ERROR", JOptionPane.ERROR_MESSAGE);
					}
					field.setText("");
					
					if (wrong == 9 && flag3 == 0)
					{
						flag3 = 1;
						JOptionPane.showMessageDialog(null,"1 wrong guess away from losing! Choose carefully.", "Warning",JOptionPane.WARNING_MESSAGE);
					}
					if (wrong == 8 && flag4 == 0)
					{
						flag4 = 1;
						JOptionPane.showMessageDialog(null, "The Noose is getting tighter!", "Uh Oh...", JOptionPane.INFORMATION_MESSAGE);
					}
					if (wrong == 2 && flag5 == 0)
					{
						flag5 = 1;
						JOptionPane.showMessageDialog(null, "You're not very good at this game, are you?", "hmmmm...", JOptionPane.PLAIN_MESSAGE);
					}
					if (right == word.length())
					{
						JOptionPane.showMessageDialog(null, "YOU WIN!!! Please refresh to play again.", "Congratulations", JOptionPane.PLAIN_MESSAGE);
					}
					repaint();
					if (wrong == 10)
					{
						JOptionPane.showMessageDialog(null, "It seems you are a complete failure... Please refresh to play again.", "Failure!!!", JOptionPane.PLAIN_MESSAGE);
					}
				}	
			}
		}
		);	
			
			
		field.addActionListener( 
		
		new ActionListener(){
			public void actionPerformed(ActionEvent event)
			{
				z = field.getText();
				z.matches("\\D{1}");
				flag = 0;
		
				for (i = 0; i < word.length(); i++)
				{
					if (z.matches("\\D{1}") == true)
					{
						if (z.charAt(0) == word.charAt(i))
						{
							flag = 1;
							c[i] = 1;
							rightLetters[i] = z;
							
							right++;
							count4 = 0;
					
							flag6 = 1;
						}
						else if (i == word.length() - 1 && flag == 0)
						{
							wrong++;
							flag = 1;
							if (incorrect == null)
							{
								incorrect = z;
								incorrect += " ";
							}
							else
							{
								for (j = 0; j < incorrect.length(); j++)
								{
									if (incorrect.charAt(j) == z.charAt(0))
									{
										flag2 = 1;
										count2++;
									}
								}
								
								if (flag2 == 0)
								{
									incorrect += z;
									incorrect += " ";
								}
								else
								{
									flag2 = 0;
								}
							}
							if (count2 != 0)
							{
								wrong--;
								count2 = 0;
							}
						}
					}
					else
					{
						flag7 = 1;
					}
					if (flag7 == 1)
					{
						flag7 = 0;
						JOptionPane.showMessageDialog(null, "Please only enter 1 letter at a time, and NO numbers please.", "ERROR", JOptionPane.ERROR_MESSAGE);
					}
					field.setText("");
					
					
					if (wrong == 9 && flag3 == 0)
					{
						flag3 = 1;
						JOptionPane.showMessageDialog(null,"1 wrong guess away from losing! Choose carefully.", "Warning",JOptionPane.WARNING_MESSAGE);
					}
					if (wrong == 8 && flag4 == 0)
					{
						flag4 = 1;
						JOptionPane.showMessageDialog(null, "The Noose is getting tighter!", "Uh Oh...", JOptionPane.INFORMATION_MESSAGE);
					}
					if (wrong == 2 && flag5 == 0)
					{
						flag5 = 1;
						JOptionPane.showMessageDialog(null, "You're not very good at this game, are you?", "hmmmm...", JOptionPane.PLAIN_MESSAGE);
					}
					if (right == word.length())
					{
						JOptionPane.showMessageDialog(null, "YOU WIN!!! Please refresh to play again.", "Congratulations", JOptionPane.PLAIN_MESSAGE);
					}
					repaint();
					if (wrong == 10)
					{
						JOptionPane.showMessageDialog(null, "It seems you are a complete failure... Please refresh to play again.", "Failure!!!", JOptionPane.PLAIN_MESSAGE);
					}
				}
	        }
		}
		);
	}
	
	public void paint (Graphics g)
	{
		super.paint(g);
		
		g.drawString ("Right: " + String.valueOf(right), 950, 700);
		g.setColor(Color.black);
		if (wrong >= 1)
		g.drawOval(100, 100, 80, 80);
		if (wrong >= 2)
		g.drawLine(140, 180, 140, 280);
		if (wrong >= 3)
		g.drawLine(140, 200, 180, 240);
		if (wrong >= 4)
		g.drawLine(140, 200, 100, 240);
		if (wrong >= 5)
		g.drawLine(140, 280, 170, 340);
		if (wrong >= 6)
		g.drawLine(140, 280, 110, 340);
		if (wrong >= 7)
		g.drawLine(120, 160, 160, 160);
		if (wrong >= 8)
		{
			g.drawLine(120, 125, 135, 140);
			g.drawLine(120, 140, 135, 125); 
		}
		if (wrong >= 9)
		{
			g.drawLine(150, 125, 165, 140);
			g.drawLine(150, 140, 165, 125);
			
		}
		if (wrong >= 10)
		{
			g.drawArc(145, 148, 15, 25, 0, -180); 
			g.setColor(Color.pink);
			g.fillArc(145, 149, 16, 24, 0, -180);
			g.setColor(Color.black);
		}
		
		g.setFont(new Font("Courier New", Font.BOLD, 50));
		
		g.drawString("Hangman", 60, 70);
		x = 455;
		y = 180;
		g.setFont(new Font("Courier New", Font.PLAIN, 25));
		g.drawString(subject, 455, 70);
		for (i = 0; i < word.length(); i++)
		{
			
			if (x >= 950)
			{
				y += 35;
				x = 455;
			}
			if (word.charAt(i) == ' ')
			{
				x1 = x;
				for (j = i + 1; j < word.length(); j++)
				{
					if (word.charAt(j) == ' ')
					{
						x1 += (35 * count);
						if (x1 >= 950)
						{
							y += 35;
							x = 455;
						}
						j = word.length();
					}
					else
					{
						count++;
					}
				}
				if (x != 455)
				{
					x += 35;
				}
			}
			else
			{
				g.drawLine(x, y, x + 20, y);
				a[i] = x;
				b[i] = y;
				x += 35;
			}
		}
		g.drawString("Incorrect letters: ", 455, y + 100);
		g.drawLine(455, y + 105, 720, y + 105);
		
		for (i = 0; i < word.length(); i++)
		{
			if (c[i] == 1 && rightLetters[i] == " ")
			{
				g.drawString(z, a[i], b[i]);
			}
			else
			{
				g.drawString(rightLetters[i], a[i], b[i]);
			}
		}
		
		g.drawString(incorrect, 455, y + 125);
	}	
}

-------------------------------------------------------------------------------

Hangman.html

<APPLET
    CODE = Hangman.class
    WIDTH = 1000
    HEIGHT = 800
>
</APPLET>

<marquee direction=right> <i><b><font size = 10> HANG MAN!!!!!!!</font></i></b></marquee>

------------------------------------------------------------------------------

The Hangman.class and the Hangman.html are both in the public_html folder.
Also, the Hangman.class is saved as a CLASS file (same as binary format?).

Any further input would be highly appreciated.

Thanks a lot!!
sciprog1

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

hey what about the quotes??
Shouldn't it be

<APPLET
CODE = "Hangman.class"
WIDTH = 1000
HEIGHT = 800
>
</APPLET>

?

the .class in there looks suspicious to me...
I never create applets (well, not for the last 12 year or so) but if the applet calling syntax is like any other java tooling syntax you don't want to call it with the .class extension at all.

What EXACTLY does the error say? Most likely it says something like "can't find class Hangman.class" which would indicate it's searching for a class called "class" in a package called "Hangman".

Hello s_sridhar,

Thanks for the reply!!

I did change it to "Hangman.class" and I still get the "ClassNotFound Exception : Hangman.class" error.

I did run a test to ensure that I have the latest JRE.

Not sure what else can be done.

If possible, kindly let me know.

Thank you so much!!
sciprog1

Hello adatapost,

Thanks a lot for the reply!!

Hangman.class and Hangman.html reside in the public_html folder. This is where all the other files of my webpage are included.

I would appreciate any further input!

Thanks a lot!!
sciprog1

This article has been dead for over six months. Start a new discussion instead.