jav program circles in rectangles
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;
for(int h=0;h<20;h++){
Rectangle R= new Rectangle(i,j,k,l);
g2.draw(R);
Ellipse2D.Double E=new Ellipse2D.Double(i,j,k,l);
g2.draw(E);
i+=11;j+=9;k+=11;l+=9;
}
}
}
////////////////////
Output is
No comments:
Post a Comment