0

How to close my opened GUI form and open another GUI form with just a button in first GUI form. this is my first GUI form

package com.company;

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

public class FirstPageGui extends JFrame implements ActionListener {

    private Container c;
    private JLabel title;

    private JButton signup;
    private JButton signin;

    public FirstPageGui(){
        c = getContentPane();
        c.setLayout(null);

        setTitle("University Management System");
        setBounds(300,90,700,600);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        title = new JLabel("Welcome to University Management System");
        title.setFont(new Font("Arial",Font.PLAIN,25));
        title.setSize(600,30);
        title.setLocation(100,30);
        c.add(title);

        signup = new JButton("Sign up");
        signup.setFont(new Font("Arial",Font.PLAIN,25));
        signup.setSize(200,100);
        signup.setLocation(100,100);
        signup.addActionListener(this);
        c.add(signup);

        signin = new JButton("Sign in");
        signin.setFont(new Font("Arial",Font.PLAIN,25));
        signin.setSize(200,100);
        signin.setLocation(350,100);
        signin.addActionListener(this);
        c.add(signin);

        setVisible(true);
    }
    public void actionPerformed (ActionEvent e){
        if(e.getSource()== signup){
            FirstGUI frstgui = new FirstGUI();

        }
        else if(e.getSource() == signin){
            LoginGUI lgngui = new LoginGUI();
        }

    }
}

I need to press Sign up button and close this GUI form and open new Sign up GUI form with just a code. can you solve this problem?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Jeewantha Lahiru
  • 324
  • 2
  • 4
  • 15
  • 1
    You may want to use the CardLayout, see https://stackoverflow.com/a/56140714/104891 for the details and the sample project. – CrazyCoder Jan 18 '20 at 18:52
  • `c.setLayout(null);` Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Jan 22 '20 at 13:16

0 Answers0