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.black);
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.BLUE);
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(194,95,110,110);
g2.draw(R9);
g2.setColor(Color.green);
g2.fill(R9);
Ellipse2D.Double R10= new Ellipse2D.Double(204,105,90,90);
g2.draw(R10);
g2.setColor(Color.white);
g2.fill(R10);
Ellipse2D.Double R11= new Ellipse2D.Double(65,95,110,110);
g2.draw(R11);
g2.setColor(Color.yellow);
g2.fill(R11);
Ellipse2D.Double R12= new Ellipse2D.Double(75,105,90,90);
g2.draw(R12);
g2.setColor(Color.white);
g2.fill(R12);
}
}
No comments:
Post a Comment