Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to close a frame on a button click ??

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Thanked 0 Times in 0 Posts

    Default How to close a frame on a button click ??

    hello sir,
    I want to close a frame when I press a button in this frame. Please suggest me how to do so with reference to my program ?

    This is my program :

    import javax.swing.*;
    import java.awt.event.*;

    class welcome
    public static void main(String args[])
    JFrame frame=new JFrame("Welcome to BANK");
    JButton welbutton=new JButton("Click here to Enter PIN");

    welbutton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    JOptionPane.showInputDialog(null, "Enter PIN", "Enter PIN", 1);

    JPanel panel=new JPanel();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: How to close a frame on a button click ??

    Thread moved from Java Theory and Questions.

    See the API for JFrame, in particular the setVisible and/or dispose methods.

Similar Threads

  1. [SOLVED] Set Invisible or close a frame
    By Souperk in forum Java Theory & Questions
    Replies: 9
    Last Post: November 30th, 2011, 11:56 AM
  2. add JTextField with a click of button
    By A4Andy in forum AWT / Java Swing
    Replies: 1
    Last Post: August 31st, 2011, 07:34 AM
  3. Opening a new frame on close.
    By Zein in forum Java Theory & Questions
    Replies: 1
    Last Post: August 24th, 2011, 03:25 PM
  4. Trying to add a close button
    By coyboss in forum Java Theory & Questions
    Replies: 5
    Last Post: February 12th, 2011, 03:28 PM
  5. close JDialog on button click
    By Christophe in forum AWT / Java Swing
    Replies: 4
    Last Post: April 4th, 2010, 11:04 PM