Results 1 to 3 of 3
  1. #1
    Prezza is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default A few GUI questions.

    Hi there. I'm busy working on a GUI project. For the project, I have to make a very basic gui system that a business would use to do a few tasks.

    Essentially I have a start-up screen that asks what the user would like to do. 3 buttons are present - make a transaction, check stock levels and check debtors. If I click on one of the buttons it takes you to the screen of the option that you chose.

    Now this is working fine for my second option, but having done the exact same thing for the first, it doesn't open the relevant screen. Button action code is:

    private void butMakeATransactionActionPerformed(java.awt.event. ActionEvent evt) {
    setVisible(false);
    makeATransaction mt=new makeATransaction();
    mt.setVisible(true);
    }

    private void butCheckStockLevelsActionPerformed(java.awt.event. ActionEvent evt) {
    setVisible(false);
    checkStockLevels check=new checkStockLevels();
    check.setVisible(true);
    }
    The second private void isn't opening the relevant screen, whereas the first one is. For the second one, it is completing the first command (setvisible(false);) but not initiating the new screen.

    I work in netbeans.

    Any help would be appreciated!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: A few GUI questions.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: A few GUI questions.

    Quote Originally Posted by Prezza View Post
    Button action code is:

    Java Code:
    private void butMakeATransactionActionPerformed(java.awt.event.ActionEvent evt) {
      setVisible(false);
      makeATransaction mt = new makeATransaction();
      mt.setVisible(true);
    }
    
    private void butCheckStockLevelsActionPerformed(java.awt.event.ActionEvent evt) {
      setVisible(false);
      checkStockLevels check = new checkStockLevels();
      check.setVisible(true);
    }
    The second private void isn't opening the relevant screen, whereas the first one is. For the second one, it is completing the first command (setvisible(false);) but not initiating the new screen.
    You're creating a makeATransaction object, mt, but I don't see where you're adding it to any part of your GUI. Assuming that this is a Swing application, in order to show a component, it must be added to a container that is part of the hierarchy that ultimately leads to a top-level window such as a JFrame, JApplet, JDialog, etc..., and you're not doing that. Also, if you swap components in and out like this, you have to be sure that the container's layout manager will like you're doing this. Also you'd need to call revalidate() and repaint() on the container.

    If this were my project, I'd try to save a lot of time and trouble by using a CardLayout to allow me to swap views. There's a good tutorial on this that Google will help you find. I recommend that you have a look at it.

    Other suggestions: don't use quote tags when posting code or it will look like this:
    private void butCheckStockLevelsActionPerformed(java.awt.event. ActionEvent evt) {
    setVisible(false);
    checkStockLevels check = new checkStockLevels();
    check.setVisible(true);
    }
    rather than like this:

    Java Code:
    private void butCheckStockLevelsActionPerformed(java.awt.event.ActionEvent evt) {
      setVisible(false);
      checkStockLevels check = new checkStockLevels();
      check.setVisible(true);
    }
    Also, consider giving your question a more helpful title. "A few GUI questions" is a very broad title and doesn't succinctly summarize what the problems specifically are. Better would be something like, "Problem getting swapped Swing components to show." or something like that. These suggestions are all contained in the links that Darryl gave you.
    Last edited by Fubarable; 10-27-2012 at 09:37 PM. Reason: Correction per advice of Darryl

Similar Threads

  1. Questions about app
    By newProgrammer in forum Android
    Replies: 0
    Last Post: 10-16-2012, 05:42 PM
  2. 3 questions
    By silverglade in forum New To Java
    Replies: 11
    Last Post: 05-09-2011, 03:17 PM
  3. Various questions
    By benn22 in forum New To Java
    Replies: 2
    Last Post: 02-11-2011, 02:56 AM
  4. Need help with some questions
    By El_Davidos in forum New To Java
    Replies: 5
    Last Post: 11-23-2010, 10:13 AM
  5. questions for 1yr exp
    By rahaman.athiq in forum Java Servlet
    Replies: 2
    Last Post: 11-26-2008, 01:13 AM

Posting Permissions

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