Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Exit method for a button

807600Nov 25 2007 — edited Nov 25 2007
i have a GUI where I created a button exitBtn and I want to add the functionality to the button when it is clicked it exits the program.
Below is the code for creating the button and then the second part is the method but I do not know how to code the exit method.

 JButton exitBtn = new JButton("Click To Exit");
        exitBtn.addActionListener(new ExitAction());
        JPanel btn1Panel = new JPanel();
        btn1Panel.add(exitBtn);
        add(btn1Panel);
private class ExitAction implements ActionListener
    {
        public void actionPerformed(ActionEvent event)
        {
            
        } // end method actionPerformed

    } // end class ExitAction
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 23 2007
Added on Nov 25 2007
15 comments
160 views