Shaldares Grasshopper
Joined: 04 Nov 2006 Posts: 19 Location: Everywhere in the Salt Lake Valley, Utah
|
Posted: Thu Nov 13, 2008 11:35 am Post subject: Calling a method from a separate class... |
|
|
So I got bored and decided to try to make pong in Java, but I'm having some problems calling a method from a separate class. The class imports just fine, it just gives me hell when I try to use a method. Here are relevant snippets of code:
| Code: | import key.KeyListen; //SOB
public class Pong extends Applet{
public void paint (Graphics g) {
.....
KeyListen KL = new KeyListen();
.......
addKeyListener(new KeyListen()); //SOB
KL.keyPressed(KeyEvent);
......
// and from the other class....
package key;
import java.awt.*;
import java.awt.event.*;
public class KeyListen extends KeyAdapter{
public void keyPressed(){
|
And here is the error I am getting:
Pong.java:24: cannot find symbol
symbol : method keyPressed()
location: class key.KeyListen
KL.keyPressed();
As far as I can tell I have it coded out so that it should be able to access this method, but I haven't been able to get around this error. I'm sure it has to be some pointless mistake, but I've been working with this for like 2 hours and can't seem to figure it out.
Am I doing something wrong? or does my code just overall suck? lol |
|