I know that it is weird to answer my own question, but...
I figured it out. You have to make your class abstract, and you can declare abstract methods to make methods "parameters" to have it behave like a KeyListener declaration. Abstract methods are declared like this:
abstract ReturnType name(Parameter p);
and behave exactly like methods when called. For a full example:
//The abstract keyword enables abstract methods to work with this class.
abstract class Foo {
//Just a random variable and a constructor to initialize it
int blah;
public Foo(int blah) {
this.blah = blah;
}
//An abstract method
abstract void doStuff();
//Example with a parameter
abstract void whatDoIDoWith(int thisNumber);
//A normal method that will call these methods.
public void doThings() {
//Call our abstract method.
doStuff();
//Call whatDoIDoWith() and give it the parameter 5, because, well... 5!
whatDoIDoWith(5);
}
}
When you try to instance an abstract class like a normal class, Java will freak out.
Foo f = new Foo(4);
What you will have to do is something like this:
Foo f = new Foo(4) {
@Override
void doStuff() {
System.out.println("Hi guys! I am an abstract method!");
}
@Override
void whatDoIDoWith(int thisNumber) {
blah += thisNumber;
System.out.println(blah);
}
}; //Always remember this semicolon!
Note that you need to include all of the abstract methods here, not just some of them. Now, let's try this:
public class Main {
public static void main(String[] args) {
//Instance foo.
Foo f = new Foo(4) {
@Override
void doStuff() {
System.out.println("Hi guys! I am an abstract method!");
}
@Override
void whatDoIDoWith(int thisNumber) {
blah += thisNumber;
System.out.println(blah);
}
};
//Call our method where we called our two abstract methods.
foo.doThings();
}
}
This prints the following to the console:
Hi guys! I am an abstract method!
9