troubleshooting Question

Why are my objects un-initializing?

Avatar of Javin007
Javin007Flag for United States of America asked on
Java
7 Comments1 Solution141 ViewsLast Modified:
So I have a fairly simple class (the "events" are just extensions off of the listeners on the parent window object):

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?");
	}
	
}


So what happens here is that when run, it pops up a window.  I click the window.  Then I click the close button in the upper right-hand corner.  This is the Debug output:

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?

Why is the "KeyWatcher" object being dropped?  I feel like it has to be something obvious that I'm missing.
ASKER CERTIFIED SOLUTION
mccarl
IT Business Systems Analyst / Software Developer
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros