This is main class
package graphs;
import javax.swing.*;
public class Graphs {
public static void main(String[] args) {
String title="ALLAH IS ONE";
JFrame f= new JFrame();
f.setSize(700,700);
f.setTitle(title);
paints P= new paints();
f.add(P);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
After writing main class create a class of paints and call it in main class
package graphs;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class paints extends JComponent {
public void
paint(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
Ellipse2D.Double R= new Ellipse2D.Double(128,20,110,110);
g2.draw(R);
g2.setColor(Color.blue);
g2.fill(R);
Ellipse2D.Double R2=
new Ellipse2D.Double(138,30,90,90);
g2.draw(R2);
g2.setColor(Color.white);
g2.fill(R2);
Ellipse2D.Double R3= new Ellipse2D.Double(12,20,110,110);
g2.draw(R3);
g2.setColor(Color.green);
g2.fill(R3);
Ellipse2D.Double R4=
new Ellipse2D.Double(22,30,90,90);
g2.draw(R4);
g2.setColor(Color.white);
g2.fill(R4);
Ellipse2D.Double R7= new Ellipse2D.Double(244,20,110,110);
g2.draw(R7);
g2.setColor(Color.red);
g2.fill(R7);
Ellipse2D.Double R8=
new Ellipse2D.Double(254,30,90,90);
g2.draw(R8);
g2.setColor(Color.white);
g2.fill(R8);
Ellipse2D.Double R9= new Ellipse2D.Double(244,121,110,110);
g2.draw(R9);
g2.setColor(Color.red);
g2.fill(R9);
Ellipse2D.Double R10=
new Ellipse2D.Double(254,131,90,90);
g2.draw(R10);
g2.setColor(Color.white);
g2.fill(R10);
Ellipse2D.Double R11= new Ellipse2D.Double(12,121,110,110);
g2.draw(R11);
g2.setColor(Color.green);
g2.fill(R11);
Ellipse2D.Double R12=
new Ellipse2D.Double(22,131,90,90);
g2.draw(R12);
g2.setColor(Color.white);
g2.fill(R12);
Ellipse2D.Double R18= new Ellipse2D.Double(128,121,110,110);
g2.draw(R18);
g2.setColor(Color.blue);
g2.fill(R18);
Ellipse2D.Double R19=
new Ellipse2D.Double(138,131,90,90);
g2.draw(R19);
g2.setColor(Color.white);
g2.fill(R19);
}
}
No comments:
Post a Comment