I have two differnt classes' that extend from the JFrame class. I have a button on one frame that should go to the next Frame, but how would I do that?

What do you mean by "go to the next frame"?
Call a method in another class that extends JFrame?
Hide the current frame and set another one visible?

Yea I have two diffrent classes that extend JFrame. Ex. Java1, and Java2.
In Java1 I use the dispose method to close the frame when the next button is pressed. How would I know the frame has been closed in the main method, so I could set Java2 to become visible.

How would I know the frame has been closed in the main method, so I could set Java2 to become visible.

If your code is the code that closes the frame you want to know the status of, the code that closes the frame could set the state of the frame that could be tested or it could call a method to report the frame has been closed.

You need to make a small simple program that compiles and executes and shows what you want the code to do.

JFrame.isActive()

Test should be returned false if the frame has been disposed!

Here is the excerpt for Logon.java

    @Override
    public void actionPerformed(ActionEvent ect)
    {
        if(ect.getActionCommand().equals("clear"))
        {
            enterUs.setText("");
            passWor.setText("");
        }

        else if(ect.getActionCommand().equals("next"))
        {
            dispose();
        }

    }

Now here is PutData.java

public class PutData extends JFrame
{


    SendInfo send;



    JLabel enter = new JLabel("Enter the clients information");
    JPanel top = new JPanel();

    JLabel nam = new JLabel("Enter the name of the client: ");
    JTextField name = new JTextField(10);
    JPanel clientName = new JPanel();

    JLabel addr = new JLabel("Enter the address of the client: ");
    JTextField address = new JTextField(10);
    JPanel clientAddress = new JPanel();

    JPanel complete = new JPanel();

    public PutData(String title)
    {
        super(title);
        this.send = send;
        //FIX THIS
        setLayout(new BorderLayout());
        setBounds(200,200,300,200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.anchor = GridBagConstraints.NORTH;
        gbc.weighty = 1;

        top.add(enter, gbc);
        add(top, BorderLayout.NORTH);

        clientName.add(nam);
        clientName.add(name);

        clientAddress.add(addr);
        clientAddress.add(address);

        add(clientName);
        add(clientAddress);




    }



}

But now when I when I try to switch the Frame in main, it does not work.

public class Main {


    public static void main(String[] args)
    {
        Logon log = new Logon("Welcome"); //The problem is the it makes a object right away
        if(log.isActive() == false)
        {
            PutData fin = new PutData("Enter the clients information");
        }

    }

}

How do I fix this?

Thats because you're creating the object. so Logon log; wont create the frame. log = new Logon() will create the frame.

But as far as i can tell the check you do after creating the frame will run right away, it wont wait until the frame is closed. You could do an infite while loop but wouldn't it be easier to open the PutData frame in the Logon class? You can do that with a WindowListener.

You need to make a small simple program that compiles and executes and shows what you want the code to do. Not pieces of code, a full program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.