Creating Dialogs

[b][red]This message was edited by jay kay at 2006-5-26 7:33:41[/red][/b][hr]
Im having some problems creating and using dialogs.My code is pretty much based on the following:

[code]
public class Editor
{
JFrame aframe = new JFrame("Editor");

Editor()
{
aframe.setBounds(0,0,799,580);
aframe.add(new Find(this));
}

public static void main(String[] Args)
{
Editor editor = Editor();
}


public void doFind()
{
FindDialog dlg = FindDialog.createDialog(aframe,_findText,_ignoreCase );
}
}

class Find
{
Editor editor;

public void actionPerformed(ActionEvent e)
{
editor.doFind();
}
}
class FindDialog extends JDialog
{
public static FindDialog createDialog( Frame owner, String findText, boolean ignoreCase )
{
FindDialog dialog = new FindDialog( owner );

dialog.setFindText( findText );
dialog.setIgnoreCase( ignoreCase );

return dialog;
}

}
[/code]


As far as i can see i've referenced my frame correctly.But i get the following error,which seems to relate to the lines

[code]
FindDialog dlg = FindDialog.createDialog(aframe,_findText,_ignoreCase );


editor.doFind();

[/code]

My code compiles correctly and runs but when i select the button which will start up the dialog I get the folowing error.

[code]
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at MyToolBar0.doEditFind(MyToolBar0.java:165)
at EditFindAction.actionPerformed(MyToolBar0.java:265)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

[/code]


Comments

  • : [b][red]This message was edited by jay kay at 2006-5-26 7:33:41[/red][/b][hr]
    : Im having some problems creating and using dialogs.My code is pretty much based on the following:
    :
    : [code]
    : public class Editor
    : {
    : JFrame aframe = new JFrame("Editor");
    :
    : Editor()
    : {
    : aframe.setBounds(0,0,799,580);
    : aframe.add(new Find(this));
    : }
    :
    : public static void main(String[] Args)
    : {
    : Editor editor = Editor();
    : }
    :
    :
    : public void doFind()
    : {
    : FindDialog dlg = FindDialog.createDialog(aframe,_findText,_ignoreCase );
    : }
    : }
    :
    : class Find
    : {
    : Editor editor;
    :
    : public void actionPerformed(ActionEvent e)
    : {
    : editor.doFind();
    : }
    : }
    : class FindDialog extends JDialog
    : {
    : public static FindDialog createDialog( Frame owner, String findText, boolean ignoreCase )
    : {
    : FindDialog dialog = new FindDialog( owner );
    :
    : dialog.setFindText( findText );
    : dialog.setIgnoreCase( ignoreCase );
    :
    : return dialog;
    : }
    :
    : }
    : [/code]
    :
    :
    : As far as i can see i've referenced my frame correctly.But i get the following error,which seems to relate to the lines
    :
    : [code]
    : FindDialog dlg = FindDialog.createDialog(aframe,_findText,_ignoreCase );
    :
    :
    : editor.doFind();
    :
    : [/code]
    :
    : My code compiles correctly and runs but when i select the button which will start up the dialog I get the folowing error.
    :
    : [code]
    : Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    : at MyToolBar0.doEditFind(MyToolBar0.java:165)
    : at EditFindAction.actionPerformed(MyToolBar0.java:265)
    : at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    : at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    : at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    : at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    : at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
    : ce)
    : at java.awt.Component.processMouseEvent(Unknown Source)
    : at javax.swing.JComponent.processMouseEvent(Unknown Source)
    : at java.awt.Component.processEvent(Unknown Source)
    : at java.awt.Container.processEvent(Unknown Source)
    : at java.awt.Component.dispatchEventImpl(Unknown Source)
    : at java.awt.Container.dispatchEventImpl(Unknown Source)
    : at java.awt.Component.dispatchEvent(Unknown Source)
    : at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    : at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    : at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    : at java.awt.Container.dispatchEventImpl(Unknown Source)
    : at java.awt.Window.dispatchEventImpl(Unknown Source)
    : at java.awt.Component.dispatchEvent(Unknown Source)
    : at java.awt.EventQueue.dispatchEvent(Unknown Source)
    : at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    :
    : at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    : at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    : at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    : at java.awt.EventDispatchThread.run(Unknown Source)
    :
    : [/code]
    :
    :
    :
    Appearantly you forgot to initialize the _findText variable.
  • Wouldn't this just give a compiler error?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion