Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java ve Animasyon
#1
Rainbow 
Java ve Animasyon


Java'da animasyon yapmak isteyen arkadaşlara yardımcı olması ümidiyle böyle bir ders hazırlamak istedim.

Java ile çalışmak isteyen arkadaşlara Merhaba...

Aşağıda çalıştıracağınız java kodumuzla GKA(grafiksel kullanıcı arayüzü) çizip, fareyle birlikte, dikdörtgen ve kare çizebiliyoruz, her saniyede.

Aynı zamanda renk değiştiren kodumuzla birlikte, şekillerimzin renkleri de değişmektedir.

Kolay gelsin Smile*/

Code:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
/*In this section; I defined first class and adds methods using JPANEL with extends  and ı defined X and y are positions but
* they are integer also ı wrote color functions.
*/

public class a3 extends JPanel {

    private static final long serialVersionUID = 1L;
    public int posCY;
    public int posCX;
    
    
    public int posSY;
    public int posSX;
    
    public Color colorC;
    public Color colorS;
    

    
    /* This is a Constructor.Thus; it construct  my shapes both circle and rectangle,so ı defined their positions and
    color 's randomly.Also; ı used of math function in library java's*/
    
    public a3(){
        
        posSX =  (int)(Math.random()*55);
        posSY = (int)(Math.random()*55);
        posCX = (int)(Math.random()*55);
        posCY =  (int)(Math.random()*55);    
        colorS =  new Color((int)(Math.random()*155),(int)(Math.random()*155),(int)(Math.random()*155),155);
        colorC =  new Color((int)(Math.random()*55),(int)(Math.random()*55),(int)(Math.random()*55),55);
        
    }
    /*With  this function ; I draw circle and square on frame. Therefore; ı defined my shapes. They are; circle and rectangle.
     * and then ı wrote positions and ı gave an integer value for my shapes.For example; for rectangle, ı used
     * g.fillRect(posSX,posSy,50,250) etc. and tehn, ı defined their colors'.The end, ı defined circle's values.
     * For example; positions and coordinates */
    
    public void paintComponent(Graphics g){
            super.paintComponent(g);
            g.setColor(colorS);
            g.fillRect(posSX, posSY, 50, 150);
            g.setColor(colorC);
            g.fillOval(posCX, posCY, 150, 150);

    }
    /*İn this function, ı defined new Jpanel and BorderLayout and ı set their locations as a CENTER. also;
     * ı said that Frame's heading  as an "ASS3" and ı set these knowledges in canvas.This canvas has size 500,500
     * and ı clicked with mouse my shapes moving on canvas.Also; their colors changing each click.
     * Therefore; ı finished my worksheet in this week*/
    
    public static void main(String[]args){

        
        a3 ok=new a3();
        
        JPanel content=new JPanel();
        content.setLayout(new BorderLayout());
        content.add(ok,BorderLayout.CENTER);
        
        JFrame window=new JFrame("ASS3");
        window.setContentPane(content);
        window.addMouseListener(new ClickMouse(ok));
        window.setSize(500, 500);
        window.setResizable(false);
        window.setVisible(true);
        ok.repaint();
    }
    
}
/* mouse events nodify when the uses the mouse to interact with a component. Mouse events occur when the cursor
* enters or exits a component's onscreen area and when the user presses or releases one of the mouse buttons.
This function runs on mouse buttons.*/
/*Mouse click: This function Called just after the user clicks the listened-to component*/


class ClickMouse implements MouseListener{
    public a3 ok;
    public ClickMouse(a3 ok){
        this.ok = ok;
    }
    
    public void mouseClicked(MouseEvent e) {
        
        
    }
    /*Mouse Entered: This function Called just after the cursor enters the bounds of the listened-to component.*/
    public void mouseEntered(MouseEvent e) {
        
        
    }
    /* Mouse exited: This function Called just after the cursor exits the bounds of the listened-to component.*/
    public void mouseExited(MouseEvent e) {
        
        
    }
    /*Mouse pressed: This function Called just after the user presses a mouse button while the cursor is over the
     * listened-to component. (non-Javadoc)*/
    
    public void mousePressed(MouseEvent e) {
        
        
    }
    
    
    /*Mouse released: This function Called just after the user releases a mouse button after a mouse press over
     * the listened-to component. Also; this function sets new position circle and rectangle both of them.*/
    /*Also;it changing colors my shapes every click in new position.*/
    public void mouseReleased(MouseEvent e) {
        
        if(e.getButton() == 1){
            ok.colorC = ok.colorS;
            ok.posCX = ok.posSX;
            ok.posCY = ok.posSY;
            ok.posSX = e.getX();
            ok.posSY = e.getY();
            ok.colorS = new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255),255);
            ok.repaint();
            /*Also; when ı researched in this topic; ı saw that,The MouseAdapter class (the AWT adapter class) is abstract.
             * All its methods have an empty body. So a developer can define methods for events specific to the application.
             * You can also use the MouseInputAdapter class, which has all the methods available from
             * MouseListener and MouseMotionListener.This knowledges from java.sun.com.
             */
        }else if(e.getButton() == 3){
            ok.colorS = ok.colorC;
            ok.posSX = ok.posCX;
            ok.posSY = ok.posCY;
            ok.posCX = e.getX();
            ok.posCY = e.getY();
            ok.colorC = new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255),255);
            ok.repaint();
        }
        
    }
    

}
/*Referances:java.sun.com,java.tutorial.com*/
[Image: vmpt.gif]
·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙˜”*°•. || Türk Team - SaNcArHaN71 || .•°*”˜˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
Reply
#2
saolasın
Cahille oturup Bal yiyeceğine....!!!!!!
Alimle oturup kuru ekmek ye daha iyi...!!_??[Mevlana]

C#.Net %20 | Html %53 | css %24 | Java %6 | flash %10 | Asp.Net %14 | Visual Basic %3 | fireworks %49

Geliştirme önemi ne göre html & css > visual basic > java >asp.net > c #.Net
Reply
#3
Bişey değil .)
[Image: vmpt.gif]
·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙˜”*°•. || Türk Team - SaNcArHaN71 || .•°*”˜˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
Reply
#4
Услуги экскаватоа-погрузчика.
1250р машино-час
смена 7+1 работаем в выходные и в ночь.
Санкт-Петербург и ближайший пригород Всеволожск, Парголово,
Юкки, Бугры, Морозовка, Мурино.
Нал, безнал.

Контактный телефон +7 911 9241277 Станислав
или на почту gordeev-stas@list.

Пул для майнинга криптовалют на компьютере
Reply
#5
teen tube
teen videos
cute teen girls
free video teen
<a href=https://cnbc.com/2016/06/03/ceo-who-kicked-dog-on-viral-video-has-new-job-running-frozen-food-firm.html>teen por video</a>
Reply
#6
hd teen
cute teen girls
teen pics
teen p
<a href=http://www.cnbc.com/2016/06/03/ceo-who-kicked-dog-on-viral-video-has-new-job-running-frozen-food-firm.html>free video teen</a>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)

Online Shopping App
Online Shopping - E-Commerce Platform
Online Shopping - E-Commerce Platform
Feinunze Schmuck Jewelery Online Shopping