Zodiac Dev Posted September 16, 2015 Posted September 16, 2015 How would I make this into like a smaller thing, I have like 13 of these and it's getting a little long... if (comboBox1.getSelectedItem().toString().equals("Varrock-East | Logs")) { c.BANK_AREA_SELECTED = c.BANK_AREA_VEAST; c.TREE_AREA_SELECTED = c.TREE_AREA_VEAST; c.selectedTree = c.TREE; c.SELECTED_PRICE = p.getSellingPrice(c.Logs); c.Area = 1;
Isolate Posted September 16, 2015 Posted September 16, 2015 (edited) Just make an enum and 1 void of loading the selected value enum kinda example thing: public enum Locations { VARROCK_EAST_NORMAL(new Area(0,0,0,0,), new Area(1,1,1,1), "Tree", "Logs"); private Area bankArea; private Area treeArea; private String treeType; private String logs; Locations(Area bankArea,Area treeArea, String treeType, String logs){ this.bankArea = bankArea; this.treeArea = treeArea; this.treeType = treeType; } public void load(){ Global.BAKN_AREA_SELECTED = this.bankArea; Global.TREE_AREA_SELECTED = this.treeArea; Global.selectedTree = this.treeType; Global.SELECTED_PRICE = p.getSellingPrice(c.logs); } } then populate a combo box with the values of the array in a way that suits you.then you can do something like (Locations) comoBox1.getSelectedItem().load(); Edited September 16, 2015 by Isolate 1
Bobrocket Posted September 16, 2015 Posted September 16, 2015 You could just have a List<enum> which is loaded in the same order as your combobox and then just grab the selected index eg list.get(myCombo.getSelectedIndex());
Joseph Posted September 17, 2015 Posted September 17, 2015 you should use an enum for accessing similar datas of different types. The enum allows us to pre-define data. Then we create getter methods to help us grab the type of data we need. All you need to do is return the select enum variable. With that variable you can grab whatever data you need