Thanks again to you two !
My vision gets clearer!
to Greg: T_T i really did!! sry i didn't see that!
actually i changed the way it works in the last few days. i let go of the class Fenster because it didn't provide more functionality than the JFrame already does (even if it was just for exercising...). in my first version my JaNeinFenster just exited the running programm. i know there are things like optiondialogs but i wanted to try something like that myself. i changed it so has a boolean in it which just tells me if yes or no was choosen, to make it usable for any situation where a yes/no decision is needed.
in my main window i use it this way
this.addWindowListener(new BeendenListener());
...
class BeendenListener extends WindowAdapter{
public void windowClosing(WindowEvent event){
final JaNeinFenster Auswahl = new JaNeinFenster("Beenden","Wollen sie wirklich beenden?"); // wieso muss das final sein?
Auswahl.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e) {
if (Auswahl.JaoderNein==(true)){
System.exit(0);
}
}
});
}
...
where JaoderNein saves the boolean. (i know this is not runnable (again) but the programm is way more complex at this point and i want to minimze the code i post here)
it works fine but there are two things left i'm uncomfortable with.
first: why is it necessary to make Auswahl final, i read several things about he compile error"Cannot refer to a non-final variable i inside an inner class defined in a different method" but i don't understand the necessarity at all.
second: i seem to not really understand the event windowClosed. i read the oracle documentation about this and i don't really understand why it is OK to access a variable of the window (which is supposed to be closed at this time)...in my understanding this should produce an error which says that this variable doesn't exist any longer, but it works just fine...
ok i did some testing on this and it leads me to the conclusion that the object really gets destroyed AFTER everything in the windowClosed method is done; am i right with that?
to jps: very usefull advice! thanks for that; i will try to keep that in mind. i really am a beginner and i have a lot of problems when it comes to the clever use of existing structures. i lack experience with questions like "how is this or that functinality implemented in the best way?" i did a lot of work on refactoring my multiexample-programm which im writing. i try to develop a small programm which will help me in the future as a little lexicon, including intelligent structuring of class hierarchies as well as basic informations about how different data types work and things like that.
seeing things in praxis is another thing than just theoretically know the concepts in my opinion.