Jump to content

Shortening stuff


Recommended Posts

Posted

How would I make this into like a smaller thing, I have like 13 of these and it's getting a little long...

 

ab06769fa02523c9fde59e28fe719c74.png

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;
Posted (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 by Isolate
  • Like 1
Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...