Programmer's Corner Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Programmer's Corner - Forums


Calling a method from a separate class...

 
Post new topic   Reply to topic    Programmer's Corner Forum Index -> Java
Author Message
Shaldares
Grasshopper


Joined: 04 Nov 2006
Posts: 19
Location: Everywhere in the Salt Lake Valley, Utah

PostPosted: Thu Nov 13, 2008 11:35 am    Post subject: Calling a method from a separate class... Reply with quote

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.
Confused Am I doing something wrong? or does my code just overall suck? lol
Back to top
ModusPonens
if A then B, if B then C...


Joined: 22 Oct 2004
Posts: 363
Location: Baltimore

PostPosted: Sat Dec 13, 2008 1:33 pm    Post subject: Reply with quote

You are passing a parameter called KeyEvent

KL.keyPressed(KeyEvent);

but the keyPressed() method in other class does not accepted a parameter.

Is the method overloaded to also accept a parameter?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Programmer's Corner Forum Index -> Java All times are GMT - 5 Hours
Page 1 of 1

 


Powered by phpBB © 2001, 2002 phpBB Group