eclipse - display a label after the Button is clicked in Java swing -


i want display label, when button clicked. using eclipse juno. have label added , setting visible part...

wlabel = new jlabel("you , me");     wlabel .setvisible(false);     wlabel .setbounds(80, 35, 100, 25);     wlabel .setfont(new font("meiryo", font.plain, 9));     wlabel .setforeground(new color(255, 102, 21));     add(wlabel); 

the button

wbutton = new jbutton("w");     wbutton .setactioncommand("mybutton");     wbutton .addactionlistener(this);     wbutton .setfont(new font("meiryo ui", font.plain, 11));     wbutton .setbounds(10, 33, 70, 35);     wbutton .setbackground(new color(102, 51, 20));     add(wbutton); 

and here actionperformed. implemented actionlistener

public void actionperformed(actionevent e) {     // todo auto-generated method stub     if (e.getactioncommand().equals("mybutton")) {         wlabel.setvisible(true);      } } 

initially can set visibility false of label , after clicking button set visibility label.setvisible(true)

for e.g. this, note using lamba syntax java 8

import java.awt.dimension; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel;  public class btndisabled {      public static void main(string[] args) {          jframe frame = new jframe("");         jlabel label = new jlabel("you , me");         label.setvisible(false);         jpanel panel = new jpanel();         panel.add(label);          jbutton btn = new jbutton("w");     btn.addactionlistener(e -> {         if (!label.isvisible()) {             label.setvisible(true);         }     });         panel.add(btn);         frame.add(panel);         frame.setsize(new dimension(500, 500));          frame.setvisible(true);     } } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -