Results 1 to 8 of 8
  1. #1
    Karenthian is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Default Multiple interfaces to a single class?

    Gentlemen, hello!
    I'm working currently on a program that (forgetting functions of each class) takes a file full of information and then does things to it. I have two interfaces;
    fileSave
    fileLoad
    This isn't the actual name of either but it's fine for my problem. The program works by fileSave in the fileSave class making a .txt with the information in it. Once this is done, the user opens fileLoad class which has the fileLoad interface, that takes the information from the .txt file and continues working with it.
    My question is thus;
    Is it possible to have two interfaces running from one class? I would like to have something along the lines of the program prompting you to either load/create a file and then doing the right one based on user input, but from what I've tried an interface constructor has to have the same name as the class it's in. Is there a way to get around this?
    Thanks
    ~Karenthian~

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Karenthian View Post
    Gentlemen, hello!
    Hello. While this greeting applies to me, there are many here who are not "men". :)


    Is it possible to have two interfaces running from one class?
    Yes, a class can implement multiple interfaces, though be sure that you're not asking the class to do too much.


    ...but from what I've tried an interface constructor has to have the same name as the class it's in. Is there a way to get around this?
    There's no such thing as an "interface constructor". Please clarify.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,259
    Rep Power
    25

    Default

    Does the OP mean a java interface (like ActionListener) or something else?

  4. #4
    Karenthian is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Default

    Sorry, I should have clarified myself a lot...
    By interface I mean a Swing GUI (which makes a lot more sense I hope) consisting (if you care to know) of mostly buttons, labels and text fields... It will include action listeners but these are not as important to my problem.
    By constructor I mean;
    Java Code:
    new fileSave()
    which will call my file save class and go on to build the panels and various things, before displaying it all.
    Does that make my point a little better?
    ~Karenthian~
    P.S. I must admit some bias in using 'gentlemen' but I tend to use it ironically anyway, so I use it when addressing most groups, sorry about that!

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Karenthian View Post
    Sorry, I should have clarified myself a lot...
    By interface I mean a Swing GUI (which makes a lot more sense I hope) consisting (if you care to know) of mostly buttons, labels and text fields... It will include action listeners but these are not as important to my problem.
    By constructor I mean;
    Java Code:
    new fileSave()
    which will call my file save class and go on to build the panels and various things, before displaying it all.
    Does that make my point a little better?
    ~Karenthian~
    P.S. I must admit some bias in using 'gentlemen' but I tend to use it ironically anyway, so I use it when addressing most groups, sorry about that!
    You're better off keeping your GUI code and your program logic code separate, and so consider one class for the GUI and another class for your file input and output, and have the GUI (or actually its controllers -- its listeners) call the methods of an input/output class object.

  6. #6
    Karenthian is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Default

    Right... that's confused me a little...
    Basically rather than have one class with everything you're suggesting have one class that does all the real work, and another that builds the GUI and then uses action listeners to send the information to the working class, which will then do everything and send it back to the interface?
    If this is the case, would I call the interface from the working class? Doing that I guess I could use if statements (or anything really) to chose which GUI they should use depending on their choice. How would I call an interface from a different class?
    A bit more speculation... could I have both other GUI's in the same class, and just call that class but call GUI1 or GUI2 depending on need?
    ~Karenthian~

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Karenthian View Post
    Right... that's confused me a little...
    Basically rather than have one class with everything you're suggesting have one class that does all the real work, and another that builds the GUI and then uses action listeners to send the information to the working class, which will then do everything and send it back to the interface?
    Something like that. Again, beware of the term "interface" since it has specialized meaning in Java. Better to say either GUI or user interface.

    If this is the case, would I call the interface from the working class? Doing that I guess I could use if statements (or anything really) to chose which GUI they should use depending on their choice. How would I call an interface from a different class?
    Your GUI could have a MyFileIO variable that refers to an object of this tye and then the action listeners could call the methods of this object.

    A bit more speculation... could I have both other GUI's in the same class, and just call that class but call GUI1 or GUI2 depending on need?
    ~Karenthian~
    Now you're confusing me. Both what other GUI's? I thought that we're only talking about one GUI here.

  8. #8
    Karenthian is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Default

    The way I've written it is (to save space on a single GUI) there is one big GUI to put data in (we're talking 35 different variables here) and a second GUI that does things to these values once they've been input (changes them, effects all of them at once etc.).
    ~Karenthian~
    P.S. sorry about misusing 'interface', I keep forgetting that one!

Similar Threads

  1. Can Single EJB Subscribe to Multiple Topics?
    By shptlucky in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 04-22-2011, 11:30 AM
  2. Multiple Sockets on a single Port
    By Sajith in forum Networking
    Replies: 2
    Last Post: 08-16-2010, 06:31 PM
  3. Multiple Java in a single BOX
    By luke_devon in forum New To Java
    Replies: 2
    Last Post: 07-05-2010, 01:59 PM
  4. Single Tomcat Multiple Developers
    By Quentinb in forum Eclipse
    Replies: 3
    Last Post: 06-14-2010, 01:40 PM
  5. multiple users with single connection
    By nishi.kishore in forum Java Servlet
    Replies: 3
    Last Post: 09-06-2009, 03:15 PM

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
  •