CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2009
    Posts
    6

    Question Moron Trying To Open A Window

    I would like to open a window that I have designed in the Netbeans GUI editor (I forget the name of it).
    The window is called ProjectTaskWindow.java

    I have a feeling I should use the setVisible property, although I don't know how to do this.

    I would like it to be opened from a menu item.

    Than you a lot.

    I looked in Java for dummies (yes I am that crap) but I couldn't find anything useful.

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

    Re: Moron Trying To Open A Window

    setVisible is a method that you call to set the window's visible state ie you pass in true to make it visible and false to hide it.
    Code:
     
    // show the window
    myWindow.setVisible(true);
     
    ...
     
    // hide the window
    myWindow.setVisible(false);

  3. #3
    Join Date
    Dec 2009
    Posts
    6

    Exclamation Re: Moron Trying To Open A Window

    Thank you.

    Unfortunately, unless I've been particularly stupid, my theory that getVisible() was the way to do it was wrong.

    I implemented it, first I had several issues with the symbol not being found.

    Message: symbol not found
    . method setVisible(boolean)
    . Location: class.ProjectTaskWindow

    After this, I created at getVisible method on ProjectTaskWindow (at the compiler's suggestion).

    The created method appeared as follows:

    public static void setVisible(boolean b) {
    throw new UnsupportedOperationException("Not yet implemented");
    }
    Which I know is completely wrong logically. I am now back where I started.

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

    Re: Moron Trying To Open A Window

    setVisible(..) is a method defined by java.awt.Window so any class that extends this class such as JFrame, JDialog etc will have this method. If your class doesn't extend java.awt.Window then this method won't work for you unless you code it yourself. However, without more info on what you are trying to do it's hard to give detailed advice. Can you show enough of your code to show the problem (in code tags please).

  5. #5
    Join Date
    Dec 2009
    Posts
    6

    Post Re: Moron Trying To Open A Window

    The program I am writing is intended to keep track of time spent on various tasks and projects and upload it to a MySQL database, as such, the project is called TimeKeeping.

    I have two main windows:
    TimeKeepingView.java - The window which will be used for inputting data about what the user is doing at that time.

    ProjectTaskWindow.java - The window which will be used to set the lists of projects and tasks.

    I would like ProjectTaskWindow to be openable from a menu item in a menu bar at the top of TimeKeepingView. I have already added the menu item

    A call is made to a method in TimeKeepingApp by the menu item.

    In TimeKeepingApp.java:
    Code:
     @Action
        public void ShowProjectTaskWindow() {
            DisplayProjectTaskWindow();
        }
    In ProjectTaskWindow.java
    Code:
        public void DisplayProjectTaskWindow(){
            setVisible();
        }
    Also in ProjectTaskWindow.java
    Code:
        private void setVisible() {
            throw new UnsupportedOperationException("Not yet implemented");
        }
    Is this information sufficient?

    Thank you so much for your time and help.

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

    Re: Moron Trying To Open A Window

    All windows have a setVisible method that takes a boolean parameter to show or hide the window. You should not override or overload that method unless you know what you're doing. In this case, you don't need to. Just call setVisible(true) on the window instance you want to show, and setVisible(false) when you want to hide it.

    If calling these methods doesn't seem to work, the windows probably aren't set up properly.

    Teachers open the door, but you must enter by yourself...
    Chinese proverb
    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.

  7. #7
    Join Date
    Dec 2009
    Posts
    6

    Re: Moron Trying To Open A Window

    OK, in that case I must conclude that my window is not set up properly. I should probably note that I got pretty much all the code to set this window up from the NetBeans main window.

    The code for the window (which is not automatically generated) is below.
    Code:
        public ProjectTaskWindow(SingleFrameApplication app) {
            super(app);
    
            this.getFrame().setResizable(false);
    
            initComponents();
    
            // status bar initialization - message timeout, idle icon and busy animation, etc
            ResourceMap resourceMap = getResourceMap();
            int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
            messageTimer = new Timer(messageTimeout, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    statusMessageLabel.setText("");
                }
            });
            messageTimer.setRepeats(false);
            int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
            for (int i = 0; i < busyIcons.length; i++) {
                busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
            }
            busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    busyIconIndex = (busyIconIndex + 1) &#37; busyIcons.length;
                    statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
                }
            });
            idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
            statusAnimationLabel.setIcon(idleIcon);
            progressBar.setVisible(false);
    
            // connecting action tasks to status bar via TaskMonitor
            TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
            taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                public void propertyChange(java.beans.PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    if ("started".equals(propertyName)) {
                        if (!busyIconTimer.isRunning()) {
                            statusAnimationLabel.setIcon(busyIcons[0]);
                            busyIconIndex = 0;
                            busyIconTimer.start();
                        }
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(true);
                    } else if ("done".equals(propertyName)) {
                        busyIconTimer.stop();
                        statusAnimationLabel.setIcon(idleIcon);
                        progressBar.setVisible(false);
                        progressBar.setValue(0);
                    } else if ("message".equals(propertyName)) {
                        String text = (String)(evt.getNewValue());
                        statusMessageLabel.setText((text == null) ? "" : text);
                        messageTimer.restart();
                    } else if ("progress".equals(propertyName)) {
                        int value = (Integer)(evt.getNewValue());
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(false);
                        progressBar.setValue(value);
                    }
                }
            });
        }
    If the automatically generated code is needed, I can easily put it up also.

    #Edit
    Here is a link to the entire project in case it's helpful.
    http://dl.dropbox.com/u/839718/TimeKeeping%200.01.zip

    Thank you all once again.
    Last edited by ratbum; December 13th, 2009 at 04:52 PM. Reason: Put link to project in post.

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

    Re: Moron Trying To Open A Window

    It looks like the ProjectTaskWindow has a frame window you can access via the 'getFrame()' method (the 2nd line of the constructor calls it to stop it being resizable). You could try calling 'setVisible(..)' on this.

    This kind of problem is one of the main reasons most developers tend to avoid these GUI code generators - they're fine for simple, static frames and forms, but a PITA if you want to do anything dynamic.

    Writing your own GUI is not that difficult, and it's well worth learning how to do it.

    Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable techniques to solve it...
    A. Aho and J. Ullman
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  9. #9
    Join Date
    Dec 2009
    Posts
    6

    Re: Moron Trying To Open A Window

    The setResizable(false) is something that I have added which doesn't seem to work.

    I have added setVisible(), however it complains in the call to it that it cannot be referenced from a static context.

    Call (complains):
    Code:
        public void ShowProjectTaskWindow() {
            timekeeping.ProjectTaskWindow.DisplayProjectTaskWindow();
        }
    Calls to:
    Code:
        public void DisplayProjectTaskWindow(){
            this.getFrame().setVisible(true);
        }
    I see what you mean about them being a PITA, but I suspect for me writing my own may even be even more of a PITA as I would not know where to start, out of interest, and also, incase I do decide that it is necessary to do that, how is the position determined with a self-coded interface, coordinates?

    I cannot even begin to say how grateful I am for all your assistance.

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

    Re: Moron Trying To Open A Window

    Quote Originally Posted by ratbum View Post
    I have added setVisible(), however it complains in the call to it that it cannot be referenced from a static context.
    So don't call it from a static context. If you're calling it from the 'main' method, you should be calling it on an instance of the class (created with 'new'). If you're calling if from a different static method, then why? When you get an error that mentions something you don't know about, find out about it - if it's important enough to break your code, you should learn about it. See Understanding Instance and Class Members.

    Without seeing the relevant code it's hard to suggest anything more specific.

    We are what we repeatedly do. Excellence, then, is not an act, but a habit...
    Aristotle
    Last edited by dlorde; December 14th, 2009 at 07:22 PM.
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

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
  •  





Click Here to Expand Forum to Full Width

Featured