PlainColorIcon.java Source code

Java tutorial

Introduction

Here is the source code for PlainColorIcon.java

Source

// The UMLet source code is distributed under the terms of the GPL; see license.txt

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

import javax.swing.Icon;

public class PlainColorIcon implements Icon {

    private Color color;

    public PlainColorIcon(Color color) {
        this.color = color;
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {
        Color old_color = g.getColor();
        g.setColor(color);
        g.fillRect(x, y, 10, 10);
        g.setColor(old_color);
    }

    public int getIconWidth() {
        return 10;
    }

    public int getIconHeight() {
        return 10;
    }

}