Jump to content

Enum/GUI help


bigd123

Recommended Posts

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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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