Results 1 to 4 of 4
  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post How to call a class within a method

    Hi people,
    I have a program that has two classes and am trying to call one classes within a method.How can i do this coz its really confusing me

    Below is my code

    Java Code:
    package MyXenonConc;
    
    import org.jdesktop.application.Action;
    /**
     *
     * @author  MUNYA00M
     */
    public class AboutBox extends javax.swing.JDialog {
    
        /** Creates new form AboutBox */
        public AboutBox(java.awt.Frame parent) {
            super(parent);
            initComponents();
           getRootPane().setDefaultButton(closeButton);
        }
    
        @Action public void closeAboutBox() {
            setVisible(false);
            
        }
        
       /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        
        // Variables declaration - do not modify
        private javax.swing.JButton closeButton;
        private javax.swing.JLabel jLabel1;
        // End of variables declaration
    
    }
    I am supposed to call the above class in another method which is in another class.
    Anyone with an idea on how i can do thid??

    your response will be highly appreciated

    Thanx

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    do your "call" means construct a class object in another class?

    if yes,
    import this call in the other class
    AboutBox ab = new AboutBox(xxx);

  3. #3
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post

    I want when a certain button is pressed,the about box class to be called and diplay the image in the frame
    This is how i called the constructor

    Java Code:
    private void AboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                              
    // TODO add your handling code here:
     AboutBox aboutBox = new AboutBox(javax.swing.JDialog);
    
    if (aboutBox == null) {
    aboutBox = new TrendAboutBox(mainFrame);
                aboutBox.setLocationRelativeTo(mainFrame);
            }
    }
    where exactly am i goin wrong????
    Last edited by Manfizy; 03-19-2009 at 11:57 AM.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Java Code:
    AboutBox aboutBox = new AboutBox(javax.swing.JDialog);
    This is wrong. In the AboutBox class you don't have a constructor with the parameter JDialog. There is with awt Frame. You have to modify either of them on your application.

Similar Threads

  1. Call java method from jsp
    By saiphani723 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-25-2009, 11:21 AM
  2. How to call method in servet by using JSP?
    By frankjava1 in forum Java Servlet
    Replies: 2
    Last Post: 10-24-2008, 04:20 AM
  3. [SOLVED] Call method from another class name
    By antgaudi in forum New To Java
    Replies: 3
    Last Post: 10-15-2008, 12:33 AM
  4. Call Java Method
    By hussainzim in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-15-2008, 07:22 AM
  5. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 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
  •