Jump to content

Enum/GUI help


Recommended Posts

Posted

I know its not TECHNICALLY restricted to just this client but it relates here anyway. I'm trying to have a simple gui where you choose what type of fishing you want done. Right now I just have it for net fishing and fly fishing.  The first problem is, I want the enum to be displayed in the gui with a capitalized first letter and multi-line(Example "Fly Fishing".) I'm also having trouble getting what type the user selected in the main code and setting a variable depending on what it is. Here is the code:

GUI enum

enum Fish {
    NET,
    FLY;
    
    @Override
    public String toString() {
        return name().toLowerCase();
    }
}

And the only code I have for the main part:

fish = gui.getSelectedFish();

You can probably tell I'm using Explv's tutorial ?

Posted

I've found the solution, and incase anyone find this and has the same issue, heres the solution:

For the actuall enum thing is what I did:

enum Fish {
    NET("Net fishing"),
    FLY("Fly fishing");
    
	private String displayName;
	
	
    Fish(String displayName) {
        this.displayName = displayName;
    }


    @Override
    public String toString() {
    	return displayName;
    }
}

This basically just uses the string in the parenthesis as what the name displayed in the gui dropdown. 

For using the value in the code, I did this:

        fish = gui.getSelectedFish();
        if(fish == fish.FLY) {
              //code
        }

Pretty self explanatory :D

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...