Reputation: 1495
Okay, this is total noob stuff, and this is a simple concept I just cannot grasp from everything I've looked at.
Currently I have some a GUI with a JList, when you select the 1st, 2nd, 3rd or whatever thing in the list it gets the respective value from a list. However, I want to move this list to a 'data' class (or all my values are elsewhere, for easier maintainence - and yes I want them hard coded into the software).
new DefaultComboBoxModel(
new String[] { "A", "B", "C", "D", "E" });
final Double[] letterCost = { 2.5, 1, 1, 1, 2.5 };
so when someone clicks E, for example, in the JList letterCost is set to 2.5 I want to move this bit
final Double[] letterCost = { 2.5, 1, 1, 1, 2.5 };
into another class. I'm over simplifying what I'm actually doing. I just want to get my head around the concept. I've never worked with multiple classes before.
So how would I go about making a new class, having the data in that class, and have it accessed as it currently would be from my original class?
Thanks..
oh, and if I had something that changed the values (say every time someone picked a letter the value increased by 1), would that continue to work the same?
Upvotes: 0
Views: 93
Reputation: 9399
You need a reference to that class, which may either be a variable you get from the method parameters, or an instance variable in your new class. Then you use (name of the reference).letterCost.
I really suggest reading some introductory books like Head First Java.
Upvotes: 1