Results 1 to 10 of 10
  1. #1
    OMFGITSROHIT is offline Member
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

    Default Switch between forms.

    How do I switch between forms?

    In other words what is the opposite of new <classname>.setvisible(true);
    Tried using false, doesn't work.

    What is form.show() and form.hide as it was in vb, in JAVA?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    setVisible(false) works. You are likely using it incorrectly.

    But having said that, there are other and perhaps better ways to change the user's view. Often we use CardLayout to swap JPanels, often JTabbedPanes, and sometimes modal JDialogs. There are many options to explore here.

    Best of luck and welcome to the forum!

  3. #3
    OMFGITSROHIT is offline Member
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

    Default

    new Add_Dept().setVisible(false);
    new Exam_Season().setVisible(true);

    This is there in the mouse click event of Add_Dept. I think its creating a new object rather than one thats running. ;(

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by OMFGITSROHIT View Post
    Java Code:
    new Add_Dept().setVisible(false);
    new Exam_Season().setVisible(true);
    This is there in the mouse click event of Add_Dept. I think its creating a new object rather than one thats running. ;(
    Yes, you are right. You are creating a new Add_Dept object and setting its visibility to false. Meanwhile, the original and visible Add_Dept is completely unaffected by this. Solution; call setvisible(false) on a reference to the original object, OR... use one of the other suggestions that I have above.

  5. #5
    OMFGITSROHIT is offline Member
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

    Default

    I've already created the form in a java desktop application, so I don't intend on changing the layout of the form. How do I create an object of a class within the same class?

    Java Code:
    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
            // TODO add your handling code here:
    Connection con = null;
    String driver = "oracle.jdbc.driver.OracleDriver";
    String user = "system";
    String pass = "manager";
    try{
    Class.forName(driver);
    con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/test",user,pass);
    Statement s=con.createStatement();
    s.execute("commit");
    s.close();
    con.close();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    Add_Dept a= new Add_Dept();
    a.setVisible(false);
    new Exam_Season().setVisible(true);
    
    }
        }

  6. #6
    OMFGITSROHIT is offline Member
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

    Default HElp

    Hello? Someone help!?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Again, you don't want to "create" a new Add_Dept object since this will defeat the whole purpose of what you are trying to do. Again, you need a reference to the original Add_Dept object, the one that is showing. How you do this will depend on the structure of your program (and you haven't shown that to us, so we can't give you any more direct help).

    In general terms, you are trying to get a handle on a GUI object from within a control object (the button's ActionListener). One way to get the Add_Dept reference into the ActionListener is to pass it in via a constructor parameter or a setter method.

    Again, I can't give you any further details since I have no idea how your program is set up. Best of luck and HTH.

  8. #8
    OMFGITSROHIT is offline Member
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

    Default

    Lol. I just figured out two things.
    Firstly, that you didn't know this.
    Secondly the keyword I'm to use is "this"

    this.setVisible(false);

    thank you ;)

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by OMFGITSROHIT View Post
    Lol. I just figured out two things.
    Firstly, that you didn't know this.
    Didn't know what? That this was being called from within the Add_Dept GUI class itself? Then yes, you are correct I didn't know it, because you never told us, and I left my crystal ball at work. :rolleyes:

    Secondly the keyword I'm to use is "this"

    this.setVisible(false);

    thank you ;)
    Welcome.

  10. #10
    OMFGITSROHIT is offline Member
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

Similar Threads

  1. Forms in MultiPageEditorPart
    By darie20 in forum SWT / JFace
    Replies: 0
    Last Post: 02-01-2010, 01:22 PM
  2. overlapping forms
    By keerthi_y19 in forum New To Java
    Replies: 4
    Last Post: 08-26-2008, 11:30 PM
  3. Login Forms
    By dankonsoer in forum New To Java
    Replies: 1
    Last Post: 08-07-2008, 01:06 PM
  4. Replies: 2
    Last Post: 04-28-2008, 11:56 AM
  5. Forms in jsp
    By bbq in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-05-2007, 05:28 AM

Tags for this Thread

Posting Permissions

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