import java.io.Serializable; import javafx.scene.paint.Color; public class SerializableColor implements Serializable { private double red; private double green; private double blue; private double alpha; public SerializableColor(Color color) { this.red = color.getRed(); this.green = color.getGreen(); this.blue = color.getBlue(); this.alpha = color.getOpacity(); } public SerializableColor(double red, double green, double blue, double alpha) { this.red = red; this.green = green; this.blue = blue; this.alpha = alpha; } public Color getFXColor() { return new Color(red, green, blue, alpha); } private String twoDigit(int n) { String out = Integer.toString(n, 16); return n < 16? "0" + out: out; } private int intColorLevel(double d) { return (int)(Math.round(255*d)); } public String makeHexCode() { return String.format("#%s%s%s", twoDigit(intColorLevel(red)), twoDigit(intColorLevel(green)), twoDigit(intColorLevel(blue))); } public static void main(String[] args) { Color c = Color.ORANGE; SerializableColor sc = new SerializableColor(c); System.out.println(sc.makeHexCode()); } }