6 Mayıs 2015 Çarşamba

Java ' da basit paint programı yapımı

Java ' da basit bir proje ödevi olarak teslim edilebilek düzeyde basit bir paint programının kodları aşağıdaki gibidir.



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JFrame;
import javax.swing.JLabel;





public class Cizim extends JFrame  {


    private JRadioButton dugme;
    private JRadioButton dugme1;
    private JRadioButton dugme2;
    private JRadioButton dugme3;
    private JRadioButton dugme4;
    private JRadioButton dugme5;
    private JRadioButton dugme6;
    private JRadioButton dugme7;


  private int pointcount=0;

  private Point point[]=new Point[10000];

  public Cizim()
  {

      super("GRUP FSM");

      
      
        Container kont  = getContentPane();
        kont.setLayout(new FlowLayout());
        dugme=new JRadioButton("Çizim İşlemine Başla");
        kont.add(dugme);
        


        kont.setLayout(new FlowLayout());
        dugme1=new JRadioButton("Renkli Boyama");
        kont.add(dugme1);
        dugme1.contains(20, 20);


        kont.setLayout(new FlowLayout());
        dugme2=new JRadioButton("Siyah Boyama");
        kont.add(dugme2);
        

        kont.setLayout(new FlowLayout());
        dugme3=new JRadioButton("Düz Çizgi");
        kont.add(dugme3);
        

        kont.setLayout(new FlowLayout());
        dugme4=new JRadioButton("Oval Boyama");
        kont.add(dugme4);

        kont.setLayout(new FlowLayout());
        dugme5=new JRadioButton("Turkuaz Boyama");
        kont.add(dugme5);

        kont.setLayout(new FlowLayout());
        dugme6=new JRadioButton("Sarı Boyama");
        kont.add(dugme6);

        kont.setLayout(new FlowLayout());
        dugme7=new JRadioButton("Kırmızı Boyama");
        kont.add(dugme7);



      addMouseMotionListener(

              new MouseMotionAdapter(){

          public void mouseDragged(MouseEvent event)
          {
             if(pointcount<point.length)
             {

                 point[pointcount]=event.getPoint();
                 if(dugme.isSelected()){
                 pointcount++;
                 repaint();
             }}
          }


      } );

      
      setSize(1024,768);
      setVisible(true);
  }


    public void paint(Graphics g) {


        super.paint(g);

        if(dugme1.isSelected()){
        for(int i=0;i<point.length && point[i]!=null ;i++)
        {

          Color c=new Color( (int) (Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
          g.setColor(c);
          g.fillRect(point[i].x,point[i].y , 4, 4);
        }}



        if(dugme2.isSelected()){

            for(int i=0;i<point.length && point[i]!=null ;i++)
        {

          Color c=new Color(256);
          g.setColor(c);
          g.fillRect(point[i].x,point[i].y , 4, 4);
        }

        }

        if(dugme3.isSelected()){

            for(int i=0;i<point.length && point[i]!=null ;i++)
        {

          Color c=new Color(256);
          g.setColor(c);
          g.drawLine(point[i].x,point[i].y , 4, 4);
        }

        }


         if(dugme4.isSelected()){

            for(int i=0;i<point.length && point[i]!=null ;i++)
        {

          Color c=new Color(256);
          g.setColor(c);
          g.fillOval(point[i].x,point[i].y , 50, 50);
        }
        }
        
        
        if(dugme5.isSelected()){

           for(int i=0;i<point.length && point[i]!=null ;i++)
        {

          
          g.setColor(Color.CYAN);
          g.fillRect(point[i].x,point[i].y , 4, 4);
        }
        }


        if(dugme6.isSelected()){

            for(int i=0;i<point.length && point[i]!=null ;i++)
        {

          
          g.setColor(Color.YELLOW);
          g.fillRect(point[i].x,point[i].y , 4, 4);
        }
        }

        if(dugme7.isSelected()){

            for(int i=0;i<point.length && point[i]!=null ;i++)
        {


          g.setColor(Color.RED);
          g.fillRect(point[i].x,point[i].y , 4, 4);
        }
        }




    }

    public static void main (String args[])

    {

        Cizim application = new Cizim();

        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private int random() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

}

Hiç yorum yok:

Yorum Gönder