i have program complete number of classes create complex objects, custom variables , arrays of variables. want tie functionality of these classes actionperformed() method calls on buttons , other components (such jtextpanes) within netbeans gui.
do need port code ui form class? not believe since have stepped through debugging program, checking status of variables, , should be. however, when hit break point pushing 1 of 'buttons', instance of class being used in ui form 'null'. puzzling me since referencing correct instance of class until hit button.
i new netbeans gui building explains incompetence in area.
all suggestions welcome guys.
this code associated button pressing:
private void submitdetailsbuttonmouseclicked(java.awt.event.mouseevent evt) { //outputtextarea.settext("get out"); dm.dhist2.framestack[dm.dhist2.frameamount].setaccomname("win"); dm.dhist2.saveandstoreframe(); }
the 'dm' here instance of discoursemanager class (my own work) within main, here:
public static void main(string args[]) { discoursemanager dm = new discoursemanager(); java.awt.eventqueue.invokelater(new runnable() { public void run() { new dialoguemanagerui().setvisible(true); } }); dm.starttransaction(); dm.rundemo(); }
bear in mind code within ui form. declare local instance of dm @ top of form within following:
public class dialoguemanagerui extends javax.swing.jframe { public static discoursemanager dm; .... }
the instance of class being recognised, proven when reach breakpoint, @ dm.rundemo() line. once hit button , break point hit (placed 1 on button method), says dm null. hope silly error missing, since rearranging code soul-destroying add ui demo purposes.
the easiest way fix set static dm
final discoursemanager dm = new discoursemanager(); java.awt.eventqueue.invokelater(new runnable() { public void run() { dialoguemanagerui.dm = dm; new dialoguemanagerui().setvisible(true); } });
but if want cleaner way eliminating public static member,
try this
public class dialoguemanagerui extends javax.swing.jframe { private final discoursemanager dm; dialoguemanagerui(discoursemanager dm) { this.dm = dm; } ... }
and
public static void main(string args[]) { final discoursemanager dm = new discoursemanager(); java.awt.eventqueue.invokelater(new runnable() { public void run() { new dialoguemanagerui(dm).setvisible(true); } });
Comments
Post a Comment