Wednesday, 15 November 2017

java graphical prjects

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,h=1,j=1,k=1,l=1;
               for(int i=0;i<14;i++)
               {
                  Ellipse2D.Double R= new Ellipse2D.Double(d,s,d,f);
                  g2.draw(R);
                  Rectangle E= new Rectangle(s,s,a,f);
                  g2.draw(E);
                  if(i%2==0)
                  {  g2.setColor(Color.BLACK);
                      g2.fill(R);
                  }
               
                      if(i%2==1){
                      g2.setColor(Color.green
                      );
                      g2.fill(E);}
                      if(i%2==0)
                      { g2.setColor(Color.yellow);
                      g2.fill(E);}
                    if(i%2==1)
                  {    g2.setColor(Color.red);
                      g2.fill(R);
                  }
                  a+=14;s+=14;d-=30;f-=30;
                  h+=1;j+=1;k+=1;l+=1;
          
    }}
}


Output is

                  

No comments:

Post a Comment