Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.Color;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    public static Color toColor(Node n) {
        if (!n.getNodeName().equals("color")) {
            throw new IllegalArgumentException(n.getNodeName());
        }
        NamedNodeMap map = n.getAttributes();
        String s = map.getNamedItem("name").getNodeValue();
        if (s.equals("white")) {
            return Color.WHITE;
        } else if (s.equals("green")) {
            return Color.GREEN;
        } else if (s.equals("pink")) {
            return Color.PINK;
        } else if (s.equals("cyan")) {
            return Color.CYAN;
        } else if (s.equals("yellow")) {
            return Color.YELLOW;
        } else {
            return Color.WHITE;
        }
    }
}