Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.Image;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Main {
    /**
     * Converts an {@code Icon} to an {@code Image}.
     * 
     * @param icon
     *            {@code Icon} that needs to be converted
     * @return the converted {@code Image}
     */
    public static Image iconToImage(Icon icon) {
        if (icon instanceof ImageIcon)
            return ((ImageIcon) icon).getImage();
        throw new IllegalArgumentException("Unable to get Image from Icon type! [" + icon + "]");
    }
}