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;
int a=16,s=30,d=400,f=400;
for(int i=0;i<14;i++)
{
Ellipse2D.Double R= new Ellipse2D.Double(a,s,d,f);
g2.draw(R);
if(i%2==0)
{ g2.setColor(Color.BLACK);
g2.fill(R);
}
else
{ g2.setColor(Color.red);
g2.fill(R);
}
a+=14;s+=14;d-=30;f-=30;
}}
}
No comments:
Post a Comment