Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.net.URL;

import javax.swing.ImageIcon;

public class Main {
    /**
     * Loads a icon from either the file system or from a jar.
     *
     * @param clas A class used to resolve the icon's relative path name
     * @param iconPath the path relative to the clas in which to find the icon.
     * @return an image icon for the icon, or null if not found
     *
     * <pre>
     * for a directory structure like
     *  edu/
     *       mypackage/
     *          MyClass.class
     *          images/
     *             myicon.gif
     *
     * call loadImageIcon(MyClass.class, "images/myicon.gif");
     *
     * </pre>
     */
    public static ImageIcon loadImageIcon(Class clas, String iconPath) {
        ImageIcon icon = null;
        URL url = clas.getResource(iconPath);
        if (url != null) {
            icon = new ImageIcon(url);
        }
        return icon;
    }
}