swing - ActionListener not working Java -
what missing here?
public class abc extends jframe { private jbutton save = new jbutton("save"); public abc() { jpanel p = new jpanel(); save.addactionlistener(new savel()); p.add(save); container cp = getcontentpane(); p = new jpanel(); p.setlayout(new gridlayout(2, 1)); cp.add(p, borderlayout.north); } } class savel implements actionlistener { public void actionperformed(actionevent e) { system.out.println("hello"); // nothing happens } }
why doesn't actionlistener work here
you creating jpanel
, adding jbutton
it, creating new jpanel
, adding panel jframe
. need adding original panel content pane.
Comments
Post a Comment