user4108288
user4108288

Reputation:

How to clear Jtextfields on reopen after disposing the frame at first time

I am trying to make a program consisting of two frames. In the first frame, when pressing the button, the second jframe opens. After giving some input in the Jtextfield of second frame, when I reopen it after disposing this, the Jtextfield contains the input which was entered previously. I am trying to make the Jtextfield clear or null when I open the frame again. The value which was entered previously will remain in the Jtextfield even after disposing and opening the Jframe again. Here is my code.

1st Frame:

package hotel_crown;

public class Main extends javax.swing.JFrame {

public Main() {

    initComponents();

}
search_guests sr=new search_guests();

private void btn_srch_gstActionPerformed(java.awt.event.ActionEvent evt) {                                             

    sr.setVisible(true);        
}                                            

2nd Frame:

package hotel_crown;

public class search_guests extends javax.swing.JFrame {

public search_guests() {
    initComponents();
    remove();
}

private void remove()
{
    txt_cnic.setText(null);
    txt_nam.setText(null);
    txt_phone.setText(null);
}

Upvotes: 0

Views: 176

Answers (1)

user4108288
user4108288

Reputation:

I found a way by using formWindowClosed event i can use the same remove(); code to make it working..

Upvotes: 0

Related Questions