Results 1 to 9 of 9
  1. #1
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Running Modules From A Seperate Class

    As you can tell I am a super noob here! I have one class called ConstructFileNamePath and another called Info. Info has a button that I want to call a procedure from ConstrucFileNamePath
    So Info reads
    Java Code:
    private void btnOpenActionPerformed(java.awt.event.ActionEvent ect) {
    //Here is where I want to call the other procedure from the other class
    }
    Now in ConstructFileNamePath everything is under the main method? So it reads
    Java Code:
    public static void main(String[] args) {
    URL url = null;
    try
    {
    //stuff here
    }
    catch{
    //
    }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default Re: Running Modules From A Seperate Class

    You need a reference to an instance of one of the classes in the other class. Sounds like you want to create an instance of Info inside ConstructFileNamePath, then you can call any method you want.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Running Modules From A Seperate Class

    Quote Originally Posted by KevinWorkman View Post
    You need a reference to an instance of one of the classes in the other class. Sounds like you want to create an instance of Info inside ConstructFileNamePath, then you can call any method you want.
    How would I reference the class?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default Re: Running Modules From A Seperate Class

    Quote Originally Posted by jo15765 View Post
    How would I reference the class?
    Generally by pointing a variable to it.

    For example, in your above code, the ect variable is a reference to the ActionEvent class, and it gives you access to that class's methods.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Running Modules From A Seperate Class

    Quote Originally Posted by KevinWorkman View Post
    Generally by pointing a variable to it.

    For example, in your above code, the ect variable is a reference to the ActionEvent class, and it gives you access to that class's methods.
    If I modified my btnOpenActionPerformed to read like so
    Java Code:
    File file= new File("\\\\ServerName\\Folder1\\Folder2\\Data\\Excel\\Workbook1.xlsx");
    How would I pass the variable file to my ConstructFileNamePath class?

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default Re: Running Modules From A Seperate Class

    Like I said, you need a reference to an instance of ConstructFileNamePath. Then you can pass the file variable in to a constructor or a method.

    Alternatively, you could have a reference to Info inside your ConstructFileNamePath class. Then call a getter, if that makes more sense in your context.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Running Modules From A Seperate Class

    Quote Originally Posted by KevinWorkman View Post
    Like I said, you need a reference to an instance of ConstructFileNamePath. Then you can pass the file variable in to a constructor or a method.

    Alternatively, you could have a reference to Info inside your ConstructFileNamePath class. Then call a getter, if that makes more sense in your context.
    I think I am getting you now, but I am still struggling with calling the other class. This is what I have to this point and please tell me how I am faring/andor what I need to do to correct this.
    Java Code:
    public class Test1(
    private void btnOpenActionperformed(java.awt.event.ActionEvent evt) {
    String file = "\\\\ServerName\\Folder1\\Folder2\\Data\\Excel\\Workbook1.xlsx";
    Test1 fileName = new Test1();
    //Whereas GetData is the method I want to call
    fileName.GetData(file);
    }
    }
    public class ConstructFileNamePath{
    public static void main (String[] args){
    }
    public static void GetData(String var){
    //Do stuff here
    }
    }

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default Re: Running Modules From A Seperate Class

    First off, I recommend fixing your formatting- use proper naming and indentation. Methods start with a lowercase name.

    It looks to me like this would have syntax errors. Does this compile?

    I'm also not sure of your logic. Do you want to create a new instance of Test1 every time you click the button?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Running Modules From A Seperate Class

    Quote Originally Posted by KevinWorkman View Post
    First off, I recommend fixing your formatting- use proper naming and indentation. Methods start with a lowercase name.

    It looks to me like this would have syntax errors. Does this compile?

    I'm also not sure of your logic. Do you want to create a new instance of Test1 every time you click the button?
    essentially what I envision doing is having 3 buttons on the form, once for Manny, Mike, Mark. If Manny's button is pressed, here is an array of workbooks that will need to be opened/refreshed/printed and so on for all 3 buttons.

    So in my mind, yes I would want a new instance of Test1 each time the button is clicked.

Similar Threads

  1. Removing panels from a seperate class
    By RayDunster in forum New To Java
    Replies: 2
    Last Post: 01-19-2012, 07:38 PM
  2. Help displaying an array from a seperate class
    By aeon1613 in forum New To Java
    Replies: 2
    Last Post: 01-16-2011, 08:15 AM
  3. Keyboard Input In A Seperate Class?
    By FatalSylence in forum New To Java
    Replies: 6
    Last Post: 10-12-2010, 05:29 AM
  4. Adding a menu from a seperate class to a JFrame
    By minime12358 in forum Advanced Java
    Replies: 2
    Last Post: 07-23-2010, 05:50 PM
  5. Manipulating components of a seperate GUI Class
    By ribbs2521 in forum New To Java
    Replies: 1
    Last Post: 10-20-2009, 10:53 PM

Posting Permissions

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