java - How do I make an button display a dialog when I click on it? -


i have 12 buttons , each button has name of in family on it. want make buttons functional. when user clicks on name want message pop , "hello (whatever name)!" code below. can please tell me how make these buttons function way want them to. in advance.

    import javax.swing.jframe;     import javax.swing.jbutton;     import javax.swing.jpanel;     import java.awt.dimension;     import java.awt.gridlayout;      public class namebuttons{      public static void main(string[] args) throws exception {         jframe frame = new jframe("pick name");         frame.setdefaultcloseoperation(jframe.exit_on_close);         jpanel buttonpanel = new jpanel();         jpanel containerpanel = new jpanel();         buttonpanel.setlayout(new gridlayout(4,6));         buttonpanel.add(new jbutton("stephanie"));         buttonpanel.add(new jbutton("dwayne"));         buttonpanel.add(new jbutton("jennifer"));         buttonpanel.add(new jbutton("brian"));         buttonpanel.add(new jbutton("joseph"));         buttonpanel.add(new jbutton("justin"));         buttonpanel.add(new jbutton("raine"));         buttonpanel.add(new jbutton("hunter"));         buttonpanel.add(new jbutton("grayson"));         buttonpanel.add(new jbutton("abel"));         buttonpanel.add(new jbutton("janice"));         buttonpanel.add(new jbutton("bob"));         buttonpanel.setpreferredsize(new dimension(300, 400));         containerpanel.add(buttonpanel);          frame.getcontentpane().add(containerpanel);         frame.pack();         frame.setvisible(true);     } } 

instead of:

buttonpanel.add(new jbutton("stephanie")); 

do:

jbutton stephaniebutton = new jbutton("stephanie"); stephaniebutton.addactionlistener(new actionlistener() {     public void actionperformed(actionevent e)     {         //do     } }); buttonpanel.add(stephaniebutton); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -