How To Print String representation of Color in Java

后端 未结 6 875
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 10:12

I have an array of colours of size n. In my program, the number of teams is always <= n, and I need to assign each team a unique color. This is my color array:

         


        
6条回答
  •  甜味超标
    2020-12-20 11:07

    If you want your NamedColor to be used as a java.awt.Color and you don't have many colors you can extend it and store the name.

    public class NamedColor extends java.awt.Color {
    
        private String name;
    
        public NamedColor(String name, java.awt.Color c) {
            super(c.getRGB());
            this.name = name;
        }
    
        public String toString() {
            return name;
        }
    }
    

提交回复
热议问题