Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package animacaosimples;
- import javax.swing.*;
- import java.awt.*;
- public class AnimacaoSimples {
- int x = 70;
- int y = 70;
- public static void main(String[] args) throws InterruptedException{
- AnimacaoSimples sistema = new AnimacaoSimples();
- sistema.mostrar();
- }
- public void mostrar() throws InterruptedException{
- JFrame janela = new JFrame();
- janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Painel desenharPainel = new Painel();
- janela.getContentPane().add(desenharPainel);
- janela.setSize(300,300);
- janela.setVisible(true);
- for (int i = 0; i < 500; i ++){
- x++;
- desenharPainel.repaint();
- try {
- Thread.sleep(20);
- } catch(InterruptedException ex){}
- }
- }
- public class Painel extends JPanel {
- @Override
- public void paintComponent(Graphics g){
- g.setColor(Color.white);
- g.fillRect(0, 0, this.getWidth(), this.getHeight());
- for(int i = 0; i < 10 ; i++){
- g.setColor(Color.red);
- g.fillOval(x+(i*30), y*2, 20, 20);
- g.setColor(Color.blue);
- g.fillOval(x+(i*30), 30+y*2, 20, 20);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement