swing - how to close a JFrame class with a button in another JFrame class in java? -
i have 2 jframes
(framea
, frameb
). frameb
can opened framea
, when open frameb
, framea
must left open. frameb
has got button (close_framea
). when button clicked close framea
.
how can it?
you can use below 2 class: tjframe , openframe close jframe class button in jframe
public class tjframe { public static openframe openwindow; public static void main(string[] args) { jframe frame = new jframe("swing frame"); jbutton button = new jbutton("open"); frame.add(button); button.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { openwindow = new openframe(); openwindow.setvisible(true); } }); frame.setdefaultcloseoperation(windowconstants.dispose_on_close); frame.setsize(350, 200); frame.setvisible(true); }} public class openframe extends jframe{ jpanel back_panel; public jbutton button = new jbutton("cross"); public openframe() { back_panel = new jpanel(); setcontentpane(back_panel); this.setsize(350, 200); button.setbounds(380, 10, 20, 20); button.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent arg0) { dispose(); } }); back_panel.add(button); }}
Comments
Post a Comment