Results 1 to 5 of 5
  1. #1
    DennisM is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default dispose() gives an "invalid method declaration"

    Hello everyone. I am new to Java and struggling a bit my way through it. My current problem is, I have created a custom MessageBox. But when I want to close/dispose it I am getting the error above. Would appreciate if anyone could give me an advice.

    Thanks.

    Java Code:
    public class CstMsgBox extends javax.swing.JDialog {
    
        /** Creates new form CstMsgBox */
        public CstMsgBox(java.awt.Frame parent, boolean modal, String labeFiller) {
            super(parent, modal);
            initComponents();
        }
    
        public void displayCstMsgBox()
        {
            this.setVisible(true);
        }
    .
    .
    .
    
    
    // when pressing the OK button, MessageBox should disappear
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }
    
        /**
         * @param args the command line arguments
         */
    
        dispose();
        
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        // End of variables declaration
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,437
    Blog Entries
    7
    Rep Power
    20

    Default Re: dispose() gives an "invalid method declaration"

    Carefully check your curly brackets: the dispose() method call isn't in a body of any method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    DennisM is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default Re: dispose() gives an "invalid method declaration"

    Thanks for help, but I still have some troubles. I thought dispose() has the same function as setVisible(false), additionally setting ressources free, which have been used by frame. But my window/MsgBox doesn't disappear, do I have to use setVisible too?

    thanks

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,437
    Blog Entries
    7
    Rep Power
    20

    Default Re: dispose() gives an "invalid method declaration"

    Quote Originally Posted by DennisM View Post
    Thanks for help, but I still have some troubles. I thought dispose() has the same function as setVisible(false), additionally setting ressources free, which have been used by frame. But my window/MsgBox doesn't disappear, do I have to use setVisible too?
    But you have a method displayCstMsgBox(); don't you use it?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    DennisM is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default Re: dispose() gives an "invalid method declaration"

    Hmm, I am a bit confused, here what I've got.

    Java Code:
    public class CstMsgBox extends javax.swing.JDialog {
    
        /** Creates new form CstMsgBox */
        public CstMsgBox(java.awt.Frame parent, boolean modal, String labeFiller) {
            super(parent, modal);
            initComponents();
        }
    
        public void displayCstMsgBox(String labelFiller)
        {
            CstOKLabel.setText(labelFiller);
            this.setVisible(true);
        }
    ...
    }
    
    private void CstOKButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }
    
        /**
         * @param args the command line arguments
         */
        // Close MessageBox
        public void hideCstMsgBox()
        {
            this.dispose();
        }
    .
    .
    }
    
    //Calling my MsgBox
    CstMsgBox box = new CstMsgBox(null,true,"Read Successful");
                            box.displayCstMsgBox("Read Successful");

Similar Threads

  1. "invalid command line parameter" error
    By MCinPgh in forum Eclipse
    Replies: 1
    Last Post: 09-09-2011, 09:03 PM
  2. Error: "Invalid character constant"
    By Turk80 in forum New To Java
    Replies: 3
    Last Post: 04-06-2011, 08:53 AM
  3. Replies: 3
    Last Post: 01-31-2011, 09:46 AM
  4. "not a statement" error to array declaration
    By SpaceMonkey in forum New To Java
    Replies: 3
    Last Post: 11-25-2010, 11:01 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 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
  •