java - add jbutton at runtime -
i building application on socket programming in swing in server listens clients , if client connected want
a button should added each client if connected on server screen
add listener on each button.for example add send message function each client
i have created thread in server listens client connections can not add jbutton @ runtime.
please reply.
is need ? :
import javax.swing.*; import java.awt.event.*; public class newbuttononruntime { static jpanel panel; static jframe frame; public static void main(string[] args){ javax.swing.swingutilities.invokelater(new runnable() { @override public void run() { frame = new jframe("add buttons"); jbutton button = new jbutton("simulate new client"); button.addactionlistener(new actionlistener(){ public void actionperformed(actionevent e) { jbutton jb = new jbutton("a new client"); jb.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { joptionpane.showmessagedialog(null, "this button action"); } }); panel.add(jb); frame.revalidate(); } }); panel = new jpanel(); panel.add(button); frame.add(panel); frame.setsize(400, 400); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setvisible(true); } }); }
}
Comments
Post a Comment