draw Resize Widgets - Java java.awt

Java examples for java.awt:Graphics2D

Description

draw Resize Widgets

Demo Code


//package com.java2s;
import java.awt.Color;

import java.awt.Graphics2D;

import java.awt.Rectangle;

public class Main {
    public static void drawResizeWidgets(Rectangle bounds, int widgetWidth,
            Color color, Graphics2D g2) {
        int offset = widgetWidth / 2;
        g2.setPaint(color);//from  www .j a va2  s.c  om
        // north-west
        int x = bounds.x - offset;
        int y = bounds.y - offset;
        g2.fillRect(x, y, widgetWidth, widgetWidth);
        // north
        x = bounds.x + bounds.width / 2 - offset;
        g2.fillRect(x, y, widgetWidth, widgetWidth);
        // north-east
        x = bounds.x + bounds.width - offset;
        g2.fillRect(x, y, widgetWidth, widgetWidth);
        // east
        y = bounds.y + bounds.height / 2 - offset;
        g2.fillRect(x, y, widgetWidth, widgetWidth);
        // south-east
        y = bounds.y + bounds.height - offset;
        g2.fillRect(x, y, widgetWidth, widgetWidth);
        // south
        x = bounds.x + bounds.width / 2 - offset;
        g2.fillRect(x, y, widgetWidth, widgetWidth);
        // south-west
        x = bounds.x - offset;
        g2.fillRect(x, y, widgetWidth, widgetWidth);
        // west
        y = bounds.y + bounds.height / 2 - offset;
        g2.fillRect(x, y, widgetWidth, widgetWidth);
    }
}

Related Tutorials