import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Arc2D;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class prog2
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(360, 360);
frame.setTitle("Prog2");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GraphicComponent component = new GraphicComponent();
frame.add(component);
frame.setVisible(true);
}
}
class GraphicComponent extends JComponent
{
public void paintComponent(Graphics g)
{
// Recover Graphics2D
Graphics2D g2 = (Graphics2D) g;
Ellipse2D.Double elli;
Arc2D.Double arc;
int h=getHeight(); //h is height of component
int w=getWidth(); //w is width of component
Ellipse2D.Double circ1 = new Ellipse2D.Double(16, 16, w*9/10, h*9/10);
g2.setColor(Color.ORANGE);
g2.fill(circ1);
Arc2D.Double arc1 = new Arc2D.Double(64, 64, w*3/5, h*3/5, 360, 480, Arc2D.PIE);
g2.setColor(Color.GREEN);
g2.fill(arc1);
Arc2D.Double arc2 = new Arc2D.Double(64, 64, w*3/5, h*3/5, 240, 120, Arc2D.PIE);
g2.setColor(Color.RED);
g2.fill(arc2);
Arc2D.Double arc3 = new Arc2D.Double(64, 64, w*3/5, h*3/5, 0, 120, Arc2D.PIE);
g2.setColor(Color.BLUE);
g2.fill(arc3);
} |