Thursday, 12 September 2013

Trouble when adding actionListener() to a JPanel

Trouble when adding actionListener() to a JPanel

I am trying to add actionListener to a JPanel in swing frame. I want to
create an event when clicking on that particular JPanel. Here is some
slice of code where in stuck down.
JLabel jlab=new JLabel("");
JPanel pnl=new JPanel();
pnl.add(jlab);
JPanel mainpnl=new JPanel();
pnl.addActionListener(new ActionListener(){public void
actionPerformed(ActionEvent ae) {jlab.setText("Clciking !!!");}});
mainpnl.add(pnl);

No comments:

Post a Comment