Sunday, October 16, 2011

How to create an oval icon in java

package com.stark;

import java.awt.Component;
import java.awt.Graphics;

import javax.swing.Icon;

/***
 * A simple icon implementation that draws ovals.
 * 
 * @author Noman Naeem
 * 
 */
public class OvalIcon implements Icon {

    private int width, height;

    public OvalIcon(int width, int height) {
        this.width = width;
        this.height = height;
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.drawOval(x, y, this.width - 1, this.height - 1);
    }

    public int getIconWidth() {
        return this.width;
    }

    public int getIconHeight() {
        return this.height;
    }
}

No comments:

Post a Comment