CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2010
    Posts
    1

    Talking A simple java question new Bie for java

    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);

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: A simple java question new Bie for java

    There are a few ways you can do this such as:

    1. 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.
    2. 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.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: A simple java question new Bie for java

    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
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured