java - Jframe form in netbean -
a>>>
package ja7; import javax.swing.jframe; /** * * @author lalit kumar */ public class gframe extends javax.swing.jframe { /** * creates new form gframe */ public gframe() { initcomponents(); } /** * method called within constructor initialize form. * warning: not modify code. content of method * regenerated form editor. */ @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code"> private void initcomponents() { jbutton1 = new javax.swing.jbutton(); jbutton2 = new javax.swing.jbutton(); jtextfield1 = new javax.swing.jtextfield(); jtextfield2 = new javax.swing.jtextfield(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); settitle("try magic"); setresizable(false); jbutton1.settext("cal"); jbutton1.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton1actionperformed(evt); } }); jbutton2.settext("fing grade "); jbutton2.setenabled(false); jbutton2.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton2actionperformed(evt); } }); jtextfield1.seteditable(false); jtextfield1.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jtextfield1actionperformed(evt); } }); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(49, 49, 49) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(jbutton2) .addcomponent(jbutton1, javax.swing.grouplayout.preferred_size, 76, javax.swing.grouplayout.preferred_size)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related, 111, short.max_value) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(jtextfield2, javax.swing.grouplayout.preferred_size, 88, javax.swing.grouplayout.preferred_size) .addcomponent(jtextfield1, javax.swing.grouplayout.preferred_size, 88, javax.swing.grouplayout.preferred_size)) .addgap(67, 67, 67)) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(73, 73, 73) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton1) .addcomponent(jtextfield2, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)) .addgap(38, 38, 38) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton2) .addcomponent(jtextfield1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)) .addcontainergap(143, short.max_value)) ); jbutton2.setvisible(false); jtextfield1.setvisible(false ); pack(); }// </editor-fold> private void jbutton1actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: int a,b; int c; a=50; b=56; c=a+b; jtextfield2.settext(integer.tostring(c)); jbutton2.setenabled(true); jbutton2.setvisible(true ); jtextfield1.setvisible(true ); } private void jtextfield1actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: } private void jbutton2actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: int c; c=integer.parseint ( jtextfield2.gettext()) ; if(c>50) { jtextfield1.settext("a ward"); } else jtextfield1.settext(" b ward"); } /** * @param args command line arguments */ public static void main(string args[]) { /* set nimbus , feel */ //<editor-fold defaultstate="collapsed" desc=" , feel setting code (optional) "> /* if nimbus (introduced in java se 6) not available, stay default , feel. * details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { (javax.swing.uimanager.lookandfeelinfo info : javax.swing.uimanager.getinstalledlookandfeels()) { if ("nimbus".equals(info.getname())) { javax.swing.uimanager.setlookandfeel(info.getclassname()); break; } } } catch (classnotfoundexception ex) { java.util.logging.logger.getlogger(gframe.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (instantiationexception ex) { java.util.logging.logger.getlogger(gframe.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (illegalaccessexception ex) { java.util.logging.logger.getlogger(gframe.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (javax.swing.unsupportedlookandfeelexception ex) { java.util.logging.logger.getlogger(gframe.class.getname()).log(java.util.logging.level.severe, null, ex); } //</editor-fold> /* create , display form */ java.awt.eventqueue.invokelater(new runnable() { public void run() { new gframe().setvisible(true); } }); } // variables declaration - not modify private javax.swing.jbutton jbutton1; private javax.swing.jbutton jbutton2; private javax.swing.jtextfield jtextfield1; private javax.swing.jtextfield jtextfield2; // end of variables declaration }
b>>
package ja7; import javax.swing.jframe; /** * * @author lalit kumar */ public class gframe extends javax.swing.jframe { /** * creates new form gframe */ public gframe() { initcomponents(); } /** * method called within constructor initialize form. * warning: not modify code. content of method * regenerated form editor. */ @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code"> private void initcomponents() { jbutton1 = new javax.swing.jbutton(); jbutton2 = new javax.swing.jbutton(); jtextfield1 = new javax.swing.jtextfield(); jtextfield2 = new javax.swing.jtextfield(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); settitle("try magic"); setresizable(false); jbutton1.settext("cal"); jbutton1.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton1actionperformed(evt); } }); jbutton2.settext("fing grade "); jbutton2.setenabled(false); jbutton2.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton2actionperformed(evt); } }); jtextfield1.seteditable(false); jtextfield1.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jtextfield1actionperformed(evt); } }); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(49, 49, 49) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(jbutton2) .addcomponent(jbutton1, javax.swing.grouplayout.preferred_size, 76, javax.swing.grouplayout.preferred_size)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related, 111, short.max_value) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(jtextfield2, javax.swing.grouplayout.preferred_size, 88, javax.swing.grouplayout.preferred_size) .addcomponent(jtextfield1, javax.swing.grouplayout.preferred_size, 88, javax.swing.grouplayout.preferred_size)) .addgap(67, 67, 67)) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(73, 73, 73) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton1) .addcomponent(jtextfield2, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)) .addgap(38, 38, 38) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton2) .addcomponent(jtextfield1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)) .addcontainergap(143, short.max_value)) ); jbutton2.setvisible(false); jtextfield1.setvisible(false ); pack(); }// </editor-fold> private void jbutton1actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: int a,b; int c; a=50; b=56; c=a+b; jtextfield2.settext(integer.tostring(c)); jbutton2.setenabled(true); jbutton2.setvisible(true ); } private void jtextfield1actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: } private void jbutton2actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: int c; c=integer.parseint ( jtextfield2.gettext()) ; jtextfield1.setvisible(true ); if(c>50) { jtextfield1.settext("a ward"); } else jtextfield1.settext(" b ward"); } /** * @param args command line arguments */ public static void main(string args[]) { /* set nimbus , feel */ //<editor-fold defaultstate="collapsed" desc=" , feel setting code (optional) "> /* if nimbus (introduced in java se 6) not available, stay default , feel. * details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { (javax.swing.uimanager.lookandfeelinfo info : javax.swing.uimanager.getinstalledlookandfeels()) { if ("nimbus".equals(info.getname())) { javax.swing.uimanager.setlookandfeel(info.getclassname()); break; } } } catch (classnotfoundexception ex) { java.util.logging.logger.getlogger(gframe.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (instantiationexception ex) { java.util.logging.logger.getlogger(gframe.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (illegalaccessexception ex) { java.util.logging.logger.getlogger(gframe.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (javax.swing.unsupportedlookandfeelexception ex) { java.util.logging.logger.getlogger(gframe.class.getname()).log(java.util.logging.level.severe, null, ex); } //</editor-fold> /* create , display form */ java.awt.eventqueue.invokelater(new runnable() { public void run() { new gframe().setvisible(true); } }); } // variables declaration - not modify private javax.swing.jbutton jbutton1; private javax.swing.jbutton jbutton2; private javax.swing.jtextfield jtextfield1; private javax.swing.jtextfield jtextfield2; // end of variables declaration }
in case a:when click on cal button(setvisible used in calbutton) jtextfield1 become visible . in case b:when click on cal button(setvisible used in fing grade)jtextfield1 become visible if resize window.
why need resize window in case b?
you need add revalidate();
this:
private void jbutton2actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: int c; c=integer.parseint ( jtextfield2.gettext()) ; jtextfield1.setvisible(true ); if(c>50) { jtextfield1.settext("a ward"); } else jtextfield1.settext(" b ward"); revalidate(); }
Comments
Post a Comment