Results 1 to 6 of 6
  1. #1
    Fluffy93 is offline Member
    Join Date
    Aug 2014
    Posts
    32
    Rep Power
    0

    Default Using a comboBox in main class from another class

    I made a thread here

    Need to use a ComboBox from another class (Beginning Java forum at JavaRanch)

    I was wondering if anyone on this forum has any knowledge on this? When my file is saved it has the values off the main gui's comboBox in variable 'env' which I then write to file using. I just need to access the comboBox in my second class so I can use it in main as I'm using the wrong one atm- if that makes sense?

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Using a comboBox in main class from another class

    You can take Swing entirely out of the picture and simplify it to this:

    I have two objects. One object needs access to a property of the other object. How do I do that?

    Are you really sure you cannot answer such an incredibly basic object oriented programming question? Because that would mean you really need to hit the books and learn the bare basics of Java before you do something as difficult as use Swing.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Fluffy93 is offline Member
    Join Date
    Aug 2014
    Posts
    32
    Rep Power
    0

    Default Re: Using a comboBox in main class from another class

    I understand how to access it - I have that set up - it won't register that the method I'm trying to get it to access exists so I'm doing something wrong just not sure what. Is it because it is not void so I should be returning something relating to the ComboBoxEnv if I wish to use it?

    In main class:
    Java Code:
    ExportImportWindow exportImport = new ExportImportWindow(dir, dir, dir, dir, me); //not sure what to pass from ExportImportWindow class
    		exportImport.ExportImportWindow(); // method I'm trying to access
    In ExportImportWindow class- I dont get why it is trying to get me to pass everything as dir when I type it in main when it doesn't pass dir here.
    [CODE]
    public ExportImportWindow(final String mode,final String env,String FromFile,String ToFile,final Main main){
    }
    [CODE]
    Last edited by Fluffy93; 10-30-2014 at 02:17 PM.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Using a comboBox in main class from another class

    That's a constructor, not a method. You have just proven my suspicions.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Using a comboBox in main class from another class

    I'm going to repeat myself this time even more specifically. This.

    Java Code:
    public ExportImportWindow(final String mode,final String env,String FromFile,String ToFile,final Main main){
    }
    is a constructor, NOT a method.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    Fluffy93 is offline Member
    Join Date
    Aug 2014
    Posts
    32
    Rep Power
    0

    Default Re: Using a comboBox in main class from another class

    Oh sorry I thought you meant the last section....but even still calling a constructor from the examples I've seen from others on the net still seems to require something similar?

    I changed my code I just put the comboBox Im trying to access in its own method called ComboBoxEnv to make things simpler
    Last edited by Fluffy93; 10-30-2014 at 03:51 PM.

Similar Threads

  1. Replies: 2
    Last Post: 01-08-2014, 06:09 PM
  2. Replies: 16
    Last Post: 11-20-2013, 01:43 PM
  3. Error: Could not find or load main class Test.class
    By java_aim in forum New To Java
    Replies: 11
    Last Post: 08-13-2013, 06:05 PM
  4. Replies: 1
    Last Post: 11-29-2012, 10:46 AM
  5. Running main method class from another main class
    By tlrocketman in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 09:30 AM

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
  •