Java Graphics Draw raiseOval(Graphics2D g2, Rectangle r, Color foreColor)

Here you can find the source of raiseOval(Graphics2D g2, Rectangle r, Color foreColor)

Description

draw an image in a rectangle

License

Apache License

Parameter

Parameter Description
gr non-null graphic context
img non-null image
r non-null rectangle
obs non-null observer

Declaration

public static void raiseOval(Graphics2D g2, Rectangle r, Color foreColor) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.*;

import java.awt.geom.Ellipse2D;

public class Main {
    /**/*from  w w  w .j  av  a2  s  .c  o m*/
     * draw an image in a rectangle
     *
     * @param gr  non-null graphic context
     * @param img non-null image
     * @param r   non-null rectangle
     * @param obs non-null observer
     */
    public static void raiseOval(Graphics2D g2, Rectangle r, Color foreColor) {
        Color background = g2.getBackground();
        Color oldColor = g2.getColor();
        Ellipse2D e = new Ellipse2D.Double(r.getX(), r.getY(), r.getWidth(), r.getHeight());
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Paint oldPaint = g2.getPaint();
        GradientPaint gp = new GradientPaint(r.x, r.y, foreColor, r.width, r.height, background, true);

        g2.setPaint(gp);
        g2.fill(e);
        g2.setPaint(oldPaint);
        g2.setColor(oldColor);

    }
}

Related

  1. paintRectShadow(Graphics g, int x, int y, int width, int height)
  2. paintShape(Shape shape, Graphics2D g2d, Color colorStroke, Stroke stroke, Color colorFill, double downsample)
  3. paintSprite(Graphics g, int x, int y, int[][] sprite, Color[] colors)
  4. prepareGraphics(Graphics g)
  5. printAll(java.awt.Graphics2D g2, java.awt.Component component)
  6. raiseRect(Graphics2D g2, Rectangle r, Color foreColor)
  7. renderByLineGraphics(JComponent c, Graphics g)
  8. renderGraphics(JComponent c, Graphics g)
  9. useAntiAliasing(Graphics2D g)