Results 1 to 5 of 5
Thread: class design/interaction problem
- 03-20-2011, 01:34 AM #1Member
- Join Date
- Mar 2011
- Rep Power
class design/interaction problem
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.
- 03-20-2011, 01:52 AM #2
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
- 03-20-2011, 02:26 AM #3Member
- Join Date
- Mar 2011
- Rep Power
- 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.
- 03-20-2011, 06:50 AM #4
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
- 03-20-2011, 06:54 AM #5
because you mentioned JButtons here's an example of what i've used on my current project:
public javax.swing.JButton menuButtons = new javax.swing.JButton; menuButtons = mbut1; menuButtons = mbut2; menuButtons = mbut3; menuButtons = mbut4; menuButtons = mbut5; menuButtons = mbut6; menuButtons = mbut7; menuButtons = 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;
- By ConMan in forum New To JavaReplies: 4Last Post: 03-16-2011, 09:38 AM
- By dinosoep in forum New To JavaReplies: 3Last Post: 12-07-2009, 11:20 AM
- By McChill in forum New To JavaReplies: 1Last Post: 05-09-2009, 11:41 PM
- By Nicholas Jordan in forum Advanced JavaReplies: 0Last Post: 07-22-2008, 09:41 PM
- By faw in forum Advanced JavaReplies: 5Last Post: 04-21-2008, 07:25 PM