Error:
error: cannot find symbol
What appears doesn\'t works:
If I write: \"InvoerVakhandler exte
The variable invoervak1
is defined in the boven
class and is not visible within InvoerVakHandler
. Since InvoerVakHandler
is registered exclusively with the invoervak1
component, you can use the source object of your ActionListener
to obtain the reference to the JTextField
:
JTextField textField = (JTextField) e.getSource();
String invoer = textField.getText();
Typically anonymous ActionListener
implementations are used. This makes the intended source clear along with its associated functionality.
The line in question in in class: InvoerVakHandler
The variable is defined in class: boven
That is why it can't find it.
I think you can get the source of the event from the ActionEvent
passed to the actionPerformed()
method.
Note that normally we use an upper-case letter to begin the name of any class and lower case to begin methods and variables. (Constants are an exception.)
The error goes away with the answers from Reimeus. However your program will not run because you created a stackoverflow. In the class Paneel you call
Boven = new boven();
However boven extends from your Paneel class. So Java needs to build a Paneel instance when building a Boven instance which will require a Paneel and so on.
Make boven extend from JPanel and your GUI starts and works.
However your output will look like this
Paneel$naam@3dee7a6c
This happens because your class "naam" did not overwritte the toString method and so Object.toString is called which produces a String based on the class name and hashCode of a Object.
So extend your naam class to this:
class naam {
private String ingevoerdNaam;
public naam( String ingevoerdNaam) {
this.ingevoerdNaam = ingevoerdNaam;
}
public String getIngevoerdNaam() {
return ingevoerdNaam;
}
public String toString() {
return ingevoerdNaam;
}
}
Hope this helps. And like mentioned already please stick to the Java Coding Conventions.