Click to See Complete Forum and Search --> : A simple java question new Bie for java
Mr.President
May 21st, 2010, 12:31 PM
I use the below code 2 show another form but when I click the button 10 time 10 forms are getting opened how to only open 1 form ?
NewJFrame1 nj = new NewJFrame1();
nj.setVisible(true);
keang
May 21st, 2010, 02:03 PM
There are a few ways you can do this such as:
Create the form once (eg in the constructor) and store the reference to it. Then to display the form you just need to call myform.setVisible(true). Calling this multiple times will have no detrimental effect.
Have a boolean variable that you set to true when the form is displayed and false otherwise. Then just before you create a new form check the variable to see if it is already displayed or not.
dlorde
May 21st, 2010, 02:03 PM
Please try to explain clearly exactly what you're trying to achieve. If necessary post a useful excerpt of the relevant code.
Programming is an explanatory activity...
R. Harper
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.