Issue
I am make a project on cars. How can I make distributor frame popup and cars frame not visible and close automatic? Kindly send any solution in simple and effective way. I have done coding this way:-
{
Cars frm1=new Cars();
Distributor frm2=new Distributor();
frm2.setVisible(true);
frm1.setVisible(false);
frm1.setDefaultCloseOperation(frm1.DISPOSE_ON_CLOSE);
}
Solution
".Please help me to how I can make distributor frame popup and cars frame is not visible and close automatic."
Ok so in Netbeans GUI Builder, you may want to do the following (this is assuming you have created two separate JFrame
form files
- In the frame that is the launching program (we'll call it
MyFrame1
) add a button to it (we'll call itjButton1
) Add a listener to the button, then the following code should be auto-generated
public void jButton1ActionPerforemd(javax.swing.ActionEvent evt) { }
In that
actionPerformed
, just instantiate the second frame (we'll call itMyFrame2
) andsetVisible(false)
toMyFrame1
.MyFrame2
should already be visible upon instantiation, so you wouldn't have tosetVisisble(true)
on itpublic void jButton1ActionPerforemd(javax.swing.ActionEvent evt) { MyFrame2 frame2 = new MyFrame2(); MyFrame1.this.setVisible(false); // You can also use MyFrame1.this.dispose(); dependind if you ever need to use that frame again }
I think this should work
Answered By - Paul Samsotha
Answer Checked By - Terry (JavaFixing Volunteer)