Repardeimaj Repardeimaj - 1 year ago 88
Java Question

java Paint component declaring shape and size outside of paintcomponent

import java.awt.Graphics;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.Timer;

public class Panel extends JPanel implements ActionListener {

Timer t = new Timer(5, this);

public Panel(){


public void paintComponent(Graphics g){


public void actionPerformed(ActionEvent e) {


I want to set the shape and size of my graphic outside of the paint component, but I don.t know how to. I have tried Oval o = new Oval but it doesn't work please help me.

Answer Source

Have you tried this ?

    Ellipse2D.Double oval = new Ellipse2D.Double(x, y, width, height);
     public void paintComponent(Graphics g)

Then you could just fill it in with g2D

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download