Get a color from the user as a String and use it in a method that accepts enum values?

前端 未结 3 1036
长发绾君心
长发绾君心 2021-01-29 10:00

How to get a color from the user as a String and use it in a method that accepts Color enum values?

The idea is to get a color that the user ch

3条回答
  •  猫巷女王i
    2021-01-29 10:15

    I would create a Map and populate it with what String color names map to which Color objects. You can use java.awt.Color's own static Color constants, e.g. colorMap.put("BLACK", Color.BLACK);, or you can insert your own mappings. Then you can take the user input and perform a lookup with get to get the proper Color object needed.

提交回复
热议问题