kyojin 0 Newbie Poster

Can somebody help me change the rectangle to an oval? I try importing the Ellipse but it doesnt work :(

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.TexturePaint;
import java.awt.geom.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageDecoder;

public class TexturePaintFill extends JPanel {
  private BufferedImage mImage;

  public TexturePaintFill() throws IOException, ImageFormatException {
    // Load the specified JPEG file.
    InputStream in = getClass().getResourceAsStream("moon.jpg");
    JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
    mImage = decoder.decodeAsBufferedImage();
    in.close();
  }

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    // a round rectangle.
    RoundRectangle2D r = new RoundRectangle2D.Float(25, 35, 150, 150, 25,
        25);
    // a texture rectangle the same size as the texture image.
    Rectangle2D tr = new Rectangle2D.Double(0, 0, mImage.getWidth(), mImage
        .getHeight());
    // the TexturePaint.
    TexturePaint tp = new TexturePaint(mImage, tr);
    // Now fill the round rectangle.
    g2.setPaint(tp);
    g2.fill(r);
  }

  public static void main(String[] args) throws Exception {
    JFrame f = new JFrame();
    f.getContentPane().add(new TexturePaintFill());
    f.setSize(350, 250);
    f.show();
  }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.