java - different GUI components keep disappearing at run time -


still quite new gui building. i'm trying make simple gui alarm clock. upon making gui keep finding different componenets keep disappearing @ run time.

    int hour=0;      int mins=0;      jlabel timer;      jlabel timer2;       public gui(){          jframe jframe = new jframe("test");         jframe.setvisible(true);         jframe.setsize(420,580);         jframe.setdefaultcloseoperation(jframe.exit_on_close);          panel p =new panel();         p.setlayout(new gridbaglayout());         p.setbackground(color.black);         jframe.add(p);          gridbagconstraints c = new gridbagconstraints();           timer = new jlabel(); timer2= new jlabel();          timer.setforeground(color.red); timer2.setforeground(color.red);         timer.settext("0" + hour); timer2.settext("0" + mins);         c.gridx=0;c.gridy=1;c.insets = new insets(10,10,0,0);p.add(timer,c);         c.gridx=1;c.gridy=1;c.insets = new insets(10,10,0,0);p.add(timer2,c);          jbutton button1 = new jbutton("^");         c.gridx=0;         c.gridy=0;         c.insets = new insets(10,10,0,0);         p.add(button1,c);           button1.addactionlistener(new actionlistener(){              public void actionperformed(actionevent e){                  string hr ="";                   if(hour==23){                      hour=0;                   }                   else{                       hour++;                   }                   if(hour <10){                      hr = "0" + hour;                  }                   else {                      hr = integer.tostring(hour);                   }                   timer.settext(hr);              }               });            jbutton button2 = new jbutton("^");         c.gridx=1;         c.gridy=0;         c.insets = new insets(10,10,0,0);         p.add(button2,c);           button2.addactionlistener(new actionlistener(){               public void actionperformed(actionevent ea){                  string min ="";                    if(mins==59){                      mins=0;                   }                   else{                       mins++;                   }                   if(mins <10){                      min = "0" + mins;                  }                   else {                      min = integer.tostring(mins);                   }                   timer2.settext(min);              }              });             jbutton button3 = new jbutton("v");         c.gridx=0;         c.gridy=2;         p.add(button3,c);           button3.addactionlistener(new actionlistener(){              public void actionperformed(actionevent eb){                  string hr ="";                    if(hour==0){                      hour=23;                   }                   else{                       hour--;                   }                    if(hour <10){                      hr = "0" + hour;                  }                   else {                      hr = integer.tostring(hour);                   }                   timer.settext(hr);              }              });            jbutton button4 = new jbutton("v");         c.gridx=1;         c.gridy=2;         c.insets = new insets(10,10,0,0);         p.add(button4,c);            button4.addactionlistener(new actionlistener(){               public void actionperformed(actionevent ea){                  string min ="";                    if(mins==0){                      mins=59;                   }                   else{                       mins--;                   }                   if(mins <10){                      min = "0" + mins;                  }                   else {                      min = integer.tostring(mins);                   }                   timer2.settext(min);              }              });             jbutton button5 = new jbutton("cancel");         c.gridx=1;         c.gridy=3;         c.insets = new insets(10,10,0,0);         p.add(button5,c);            jbutton button6 = new jbutton("ok");         c.gridx=0;         c.gridy=3;         c.insets = new insets(10,10,0,0);         p.add(button6,c);          }     public static void main(string[] args) {        gui app=new gui();     }     } 

any appreciated. still quite new this. many thanks


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -