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(300,390);
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 new class of paints
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;
g2.drawString("An intelligent face", 10, 10);
int i=1,j=1,k=1,l=1,q=1,w=1,e=1,r=1;
for(int h=0;h<20;h++){
Rectangle R= new Rectangle(i,j,k,l);
g2.draw(R);
Ellipse2D.Double E=new Ellipse2D.Double(q,w,e,r);
g2.draw(E);
q+=1;w+=2;e+=10;r+=9;
i+=3;j+=4;k+=5;l+=5;
}
}
}
Output:
No comments:
Post a Comment