...

View Full Version : What is wrong with this code?



pineappelle
04-18-2012, 05:45 PM
I have this code

/**
* @(#)slime.java
*
* slime Applet application
*
* @author
* @version 1.00 2012/4/18
*/

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class slime extends java.applet.Applet implements KeyListener {

Graphics screen, offscreen;
Image workspace;
int character_int;
slimeSprite green;

public void init() {

requestFocus();
addKeyListener(this);
workspace=createImage(600,400);
offscreen=workspace.getGraphics();
green=new slimeSprite(50,50,100,100);

}

public void keyPressed(KeyEvent event) {

character_int=event.getKeyCode();



}

public void keyReleased(KeyEvent event) {
}

public void keyTyped(KeyEvent event) {
}

public void paint(Graphics screen) {

green.getcolor(Color.green);
green.drawslime(screen);

}
}

and then this class code

import java.awt.*;
public class slimeSprite {

int x, y, height, width;
Color mycolor;

public slimeSprite(int left,int top,int h,int w) {

x=left;
y=top;
height=h;
width=w;

}

public void getcolor(Color clr) {
mycolor=clr;
}

public void drawslime(Graphics screen) {

screen.setColor(mycolor);
screen.fillOval(x,y,height,width);
screen.setColor(Color.white);
screen.fillRect(x+(height/2),y,2/height,width);

}

}

and it bring up the error: cannont find cymbol class slimeSprite.

what is wrong?

Fou-Lu
04-18-2012, 06:53 PM
During compile or runtime?
Make sure that the slimesprite is a part of the classpath available when running the applet. Easiest thing to do is simply package it up from an IDE since it will do this work for you, otherwise follow the documentation in javac: http://docs.oracle.com/javase/1.3/docs/tooldocs/win32/javac.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum