Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

import java.awt.Color;

public class Main {
    public static String getColorString(Color color) {
        StringBuffer buffer = new StringBuffer("#"); //$NON-NLS-1$
        appendComponent(buffer, color.getRed());
        appendComponent(buffer, color.getGreen());
        appendComponent(buffer, color.getBlue());
        return buffer.toString();
    }

    public static void appendComponent(StringBuffer buffer, int component) {
        String hex = Integer.toHexString(component);
        if (hex.length() == 1) {
            buffer.append('0');
        }
        buffer.append(hex);
    }
}