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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 3 of 3

Thread: Button help

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    30
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Button help

    Hello

    i'm trying to make a simple program and when i press a button i open up a new window but how do i make the old one disappear?
    can't find out how i'm doing :S

    here is my code for the window that i want to disappear
     
    import java.awt.*;
    import javax.swing.*;
     
    public class Bank {
    	public static void main(String [] args)	{
    	JFrame frame = new JFrame();
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	frame.setLayout(new FlowLayout());
    	frame.setSize(new Dimension(300, 159));
    	frame.setTitle("Login");
     
    	JButton login = new JButton();
    	login.setText("Login");
    	frame.setLayout(new BorderLayout());
    	JPanel north = new JPanel(new GridLayout(3, 3));
    	north.add(new JLabel ("Username: "));
    	north.add(new JTextField());
    	north.add(new JLabel ("Password: "));
    	north.add(new JTextField());
    	north.add(new JLabel (""));
    	north.add(login);
    	login.addActionListener(new login());
     
     
    	frame.add(north, BorderLayout.NORTH);
     
    	frame.setVisible(true);
     
    	}
    }

    hope someone can help me


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Button help

    If you want a window to "disappear" usually it's better to use a dialog such as a JDialog or the related JOptionPane. Then to make it disappear you can simply call setVisible(false) or dispose() on the dialog in the event where you want it to disappear.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    30
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Button help

    Thanks alot

Similar Threads

  1. Button tryout
    By kloek8 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 2nd, 2012, 08:28 AM
  2. Can't use button.addActionListener(this); ?
    By xdega in forum AWT / Java Swing
    Replies: 2
    Last Post: April 23rd, 2012, 09:44 AM
  3. Button disable
    By deependeroracle in forum AWT / Java Swing
    Replies: 6
    Last Post: April 22nd, 2012, 10:06 AM
  4. Help with button actionlistener
    By umerahmad in forum Java Theory & Questions
    Replies: 9
    Last Post: August 25th, 2011, 08:21 AM
  5. Action button HELP?
    By utoptas in forum Java Theory & Questions
    Replies: 8
    Last Post: August 27th, 2010, 04:32 PM