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.Document;
import org.w3c.dom.Element;

public class Main {
    private static final String TAG_NAME_BLUE = "blue";
    private static final String TAG_NAME_GREEN = "green";
    private static final String TAG_NAME_RED = "red";

    /**
     * attach (append to child) RGB to the element, in the format <red>12</red> etc
     * @param rgb
     * @param elem
     * @param doc
     */
    public static void attachRGB(Color rgb, Element elem, Document doc) {
        int r = rgb.getRed();
        int g = rgb.getGreen();
        int b = rgb.getBlue();

        //create element
        Element red = doc.createElement(TAG_NAME_RED);
        Element green = doc.createElement(TAG_NAME_GREEN);
        Element blue = doc.createElement(TAG_NAME_BLUE);

        //fill the content
        red.appendChild(doc.createTextNode(Integer.toString(r)));
        green.appendChild(doc.createTextNode(Integer.toString(g)));
        blue.appendChild(doc.createTextNode(Integer.toString(b)));

        //structure the content
        elem.appendChild(red);
        elem.appendChild(green);
        elem.appendChild(blue);
    }
}