Java

Java prog#8. How to close previous jframe on the opening of new jframe in netbeans



it’s simple just follow the below code:
First import these two files below
import java.awt.event.*;
import java.awt.*;

then write the method for close

public void close(){

WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);

}

★★★Top Online Courses From ProgrammingKnowledge ★★★
Python Programming Course ➡️ ⚫️…

21 thoughts on “Java prog#8. How to close previous jframe on the opening of new jframe in netbeans

  1. at Login.java (or whatever you named it):

    if(rs.next()){
    JOptionPane.showMessageDialog(null, "Username and Password is correct");
    rs.close();
    pst.close();

    patient_info s = new patient_info();
    s.setVisible(true);

    this.dispose(); //use this line of code which makes this entire video pointless
    }

  2. I did the public void close exactly like the video:
    public void close(){
    WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(WinClosingEvent);
    }

    But it says it can't find symbol: class WindowEvent

    Can someone please explain why?

Leave a Reply

Your email address will not be published. Required fields are marked *