java - JFrame popup not showing content -
i have classa processing , want create popup jframe classb shows statistics classa calculated. did this:
public class mainmenu extends javax.swing.jframe { public mainmenu() { initcomponents(); } private void initcomponents() { calculatebutton = new javax.swing.jbutton(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); calculatebutton.settext("calculate"); calculatebutton.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { calculatebuttonactionperformed(evt); } }); pack(); } private void calculatebuttonactionperformed(java.awt.event.actionevent evt) { new classa().calculate(); } public static void main(string args[]) { /* create , display form */ java.awt.eventqueue.invokelater(new runnable() { public void run() { new mainmenu().setvisible(true); } }); } public class classa { private int i; private classb classb; public classa(){ = 3000; classb = new classb(); classb.setvisible(true); } public void calculate(){ int percentcomplete; (int j = 0 ; j<i ; j++){ (int x = 0; x<100000 ; x++) (int y = 0; y<100000 ; y++) (int z = 0; z<100000 ; z++); percentcomplete = (int) (100 * (float)j/ (float) i); system.out.println(" "+percentcomplete); classb.setprogress(percentcomplete); } }
}
public class classb extends javax.swing.jframe { public classb() { initcomponents(); } private void initcomponents() { jpanel1 = new javax.swing.jpanel(); jprogressbar1 = new javax.swing.jprogressbar(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); jprogressbar1.setstringpainted(true); javax.swing.grouplayout jpanel1layout = new javax.swing.grouplayout(jpanel1); jpanel1.setlayout(jpanel1layout); jpanel1layout.sethorizontalgroup( jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel1layout.createsequentialgroup() .addcomponent(jprogressbar1, javax.swing.grouplayout.default_size, 370, short.max_value) .addcontainergap()) ); jpanel1layout.setverticalgroup( jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel1layout.createsequentialgroup() .addgap(39, 39, 39) .addcomponent(jprogressbar1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size) .addcontainergap(52, short.max_value)) ); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addcontainergap() .addcomponent(jpanel1, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcontainergap()) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addcontainergap() .addcomponent(jpanel1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size) .addcontainergap(181, short.max_value)) ); pack(); } public void setprogress(int x){ jprogressbar1.setvalue ( x ); } private javax.swing.jpanel jpanel1; private javax.swing.jprogressbar jprogressbar1;
}
the problem i'm facing jframe of classb appears empty window , doesn't show until processes/calculations of classa have finished. shows contents last updates data of classa. ideas or solutions?
you didn't show how call methods of classa make various calculations. can guess call of them in event dispatch thread (see the event dispatch thread details) , java cannot render until classa completes processing.
if case should run calculation in other thread. convenient way of doing using swingworker
.
Comments
Post a Comment