Results 1 to 5 of 5
  1. #1
    wotupduck is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default class design/interaction problem

    Hi,
    Im working in a project that has a front end GUI where the user can perform various options, i have created a MainMenu class to represent this, but from this menu the user can select an administer option that will open a separate Admin menu. Im struggling to identify how i can design this, at the moment my thoughts are that the MainMenu will have one Admin object that will display the admin menu, but this Admin oject will need to perfom operation on other Objects that have been created in the MainMenu class. At first i thought that i could just pass the Objects as parameters when creating the Admin oject but then after the user exits, the Admin object would have to return the other Objects in there edited state so that they are updated in the MainMenu object(which i dont know how to do) and then i thought maybe inheritance?, but I really dont know what im doing, essentially i need to access a parent classes attributes(by reference) from a child class(if that makes sense).
    apologies if i have made no sense, i've tried to explain in as much detail as i can but im just confusing myself, any help would be much appreciated.
    Thanks in advance.

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    you are not just confusing yourself...

    what i made of that was:
    - you have a problem in making a method called from one Swing object/admin button to access other Swing objects?
    - you want to pass objects through parameters to methods which can save their editted state before the program exits?
    - what is this "admin object" actually?
    - what did you say about parent/child class???

    please clarify on everything but don't write it all in one-line this time :P

  3. #3
    wotupduck is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    - I have made a MainMenu class/object which as JFrame with button objects on it, of which one is called Admin
    -For purposes of an example, say this class has an attribute called cars which is an array of 'car' objects.

    -I have a AdminMenu class which is also a JFrame with other Swing objects on it.

    -The MainMenu class is 'composed of' a AdminClass (has-a relationship)
    - So when the admin button is clicked on the main menu the admin menu is displayed.

    -How can access the cars array (by reference) from the AdminMenu class

    I hope this makes it a bit clearer and thanks for the help.

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    if the cars array is declared private, change it to public then access it in the adminmenu class by calling MainMenu.carsArray. if you can't make it public, make another array which is public and load the array of objects into that list e.g.

    public java.util.List<Cars> carList = new java.util.ArrayList<Cars>();
    carList = java.util.Arrays.asList(carsArray);

    modifying objects from the new list should also cause the original object to be modified

  5. #5
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    because you mentioned JButtons here's an example of what i've used on my current project:

    Java Code:
    public javax.swing.JButton[] menuButtons = new javax.swing.JButton[8];
    menuButtons[0] = mbut1;
    menuButtons[1] = mbut2;
    menuButtons[2] = mbut3;
    menuButtons[3] = mbut4;
    menuButtons[4] = mbut5;
    menuButtons[5] = mbut6;
    menuButtons[6] = mbut7;
    menuButtons[7] = mbut8;
    
    private javax.swing.JButton mbut1;
    private javax.swing.JButton mbut2;
    private javax.swing.JButton mbut3;
    private javax.swing.JButton mbut4;
    private javax.swing.JButton mbut5;
    private javax.swing.JButton mbut6;
    private javax.swing.JButton mbut7;
    private javax.swing.JButton mbut8;

Similar Threads

  1. Class Design Problems (BlackJack)
    By ConMan in forum New To Java
    Replies: 4
    Last Post: 03-16-2011, 08:38 AM
  2. class design
    By dinosoep in forum New To Java
    Replies: 3
    Last Post: 12-07-2009, 10:20 AM
  3. Basic Class Interaction Question
    By McChill in forum New To Java
    Replies: 1
    Last Post: 05-09-2009, 11:41 PM
  4. design question comments wanted - essential class init()
    By Nicholas Jordan in forum Advanced Java
    Replies: 0
    Last Post: 07-22-2008, 09:41 PM
  5. Pls HeLp Me (Design a class named Fan)
    By faw in forum Advanced Java
    Replies: 5
    Last Post: 04-21-2008, 07:25 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
  •