I am trying to access the focus events a component within
another component.
I present here the basic idea of what I am trying to do.
Here is a Class containing a JTextField where I want to be notified of its FocusEvents from outside the class
<code><pre>public class PageContainingJTextField extends JPanel
{
JTextField newField = new JTextField();
public PageContainigJTextField()
{
//page initialization
}
public void addFocusListener(FocusListener newListener)
{
newField.addFocusListener(newListener);
}
}</pre></code>
And the class which calls it and uses the event information.
<code><pre>public class FocusPeeker implements FocusListener
{
PageContainingJTextField newPage = new PageContainingJTextField();
public FocusPeeker()
{
//other initilization
newPage.addFocusListener(this);
}
public void gainedFocus(FocusEvent e)
{
System.out.println("JTextField lost focus");
}
pubic void lostFocus(FocusEvent e)
{
System.out.println("JTextField gained focus");
}
}</pre></code>
I think I must be missing something.
I tried it both on Linux and Windows and both times received the nullPointer exception.
TIA,
Jeff Weinheimer
[This message has been edited by Jim Yingst (edited May 26, 2000).]
another component.
I present here the basic idea of what I am trying to do.
Here is a Class containing a JTextField where I want to be notified of its FocusEvents from outside the class
<code><pre>public class PageContainingJTextField extends JPanel
{
JTextField newField = new JTextField();
public PageContainigJTextField()
{
//page initialization
}
public void addFocusListener(FocusListener newListener)
{
newField.addFocusListener(newListener);
}
}</pre></code>
And the class which calls it and uses the event information.
<code><pre>public class FocusPeeker implements FocusListener
{
PageContainingJTextField newPage = new PageContainingJTextField();
public FocusPeeker()
{
//other initilization
newPage.addFocusListener(this);
}
public void gainedFocus(FocusEvent e)
{
System.out.println("JTextField lost focus");
}
pubic void lostFocus(FocusEvent e)
{
System.out.println("JTextField gained focus");
}
}</pre></code>
I think I must be missing something.
I tried it both on Linux and Windows and both times received the nullPointer exception.
TIA,
Jeff Weinheimer
[This message has been edited by Jim Yingst (edited May 26, 2000).]