package com.peculiarhabit.application;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import com.peculiarhabit.debug.Debug;
import com.peculiarhabit.gui.Window;
import com.peculiarhabit.input.KeyWatcher;
public class MainWindow extends Window {
public static class Builder extends Window.Builder {
@Override public MainWindow build() {
return new MainWindow(this);
}
}
protected MainWindow(Builder b) {
super(b);
}
protected KeyWatcher kw = null;
@Override protected void windowInitialized() {
kw = new KeyWatcher();
Debug.print("kw is null: " + (kw == null));
}
@Override protected void mouseClicked(MouseEvent e) {
Debug.print("(click) kw is null: " + (kw == null));
}
@Override protected void windowClosing(WindowEvent e) {
Debug.print("Closing");
if (kw == null) Debug.print("Why is it null?");
}
}
00:00:00.000.113 main kw is null: false
00:00:01.597.709 AWT-EventQueue-0 (click) kw is null: true
00:00:06.287.066 AWT-EventQueue-0 Closing
00:00:06.287.235 AWT-EventQueue-0 Why is it null?
ASKER
what was your reason for using the hashcodes? What does that tell you?"hashcode()" is like an ID of the object. Each different object instance will have a different hashcode. So the code above was printing out the hashcode/ID of "this" which is the MainWindow object (note, it's NOT the KeyWatcher object). What I was expecting to see is at least 2 different hashcodes being printed out in those debug statements.
ASKER
I don't even have the KeyWatcher class anymoreYes, but do you still have MainWindow? As I aluded to above, the issues with KeyWatcher was just a symptom of a bigger problem.
ASKER
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.
TRUSTED BY
ASKER
While setting the object to "Final" kind of works (the object is now NOT initialized in the "init" event, but is in the further events) it's also not what I'm trying to do. I would prefer that I be able to create/destroy the object when I want to.
"Hanging" the main thread open (with a while loop that keeps it open as long as an "IsRunning" variable is "true") seems to get the desired result, but is that the right way to do things? Seems a wasted thread to me.