java - How do i implement a Jbutton and event listener to close the application? -


the following code...the jbutton added in gui method. need jbutton add container , eventlistener enable application close when pushed.

public class beetswk1 extends jframe{  public beetswk1(){       gui(); }  public void gui(){       flowlayout layout = new flowlayout();          layout.setalignment(flowlayout.center);      container container;     container = getcontentpane();     container.setbackground(new color(052,062,138));     container.setlayout(layout);      jlabel label = new jlabel();     label.settext ("hello world" );     label.setsize( 500, 400);             label.setfont( new font( "sanserif", font.plain, 15) );             label.sethorizontalalignment( jlabel.center );     label.setforeground(color.white);     container.add( label ); }      public static void main(string[] args) {         // todo code application logic here             dimension dimension = new dimension(500, 500);                         beetswk1 window = new beetswk1();                        window.setvisible(true);                         window.setsize(dimension);                            window.setdefaultcloseoperation(window.exit_on_close);     }      private dimension dimension(int i, int j) {         throw new unsupportedoperationexception("not yet implemented");     } } 

what's stopping you?

jbutton button = new jbutton(); button.settext("some text"); getcontentpane().add(button);  button.addactionlistener(new actionlistener() {       @override       public void actionperformed(actionevent evt) {            system.exit(0);       } }); 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -