Java Tutorial 44 (GUI) – Simple Animation

///Java Tutorial 44 (GUI) – Simple Animation

Java Tutorial 44 (GUI) – Simple Animation

FavoriteLoadingAdd to favorites

Animation is a big part of 2D games. If you want to create a video game, then you will have to learn how to make animation.

source

Java468x60
By |2020-11-18T10:37:45+00:00November 18th, 2020|Java Video Tutorials|42 Comments

42 Comments

  1. Viktor Lnt November 18, 2020 at 10:37 am - Reply

    finally someone who talks to me like I was retarded, easy to understand tutorial, gg

  2. Joel Malepe November 18, 2020 at 10:37 am - Reply

    8 years later. This' so cool

  3. L0raxeo November 18, 2020 at 10:37 am - Reply

    It's not working FOR MEEEEEE
    WHYYYYYYYYYYYYYYY IT WON'T move!!!

  4. Panav Gupta November 18, 2020 at 10:37 am - Reply

    Thank you so much
    I learnt Java but the course didn't include animation
    thanks

  5. s p November 18, 2020 at 10:37 am - Reply

    No its Ai will be teaching yuuu

  6. 1 November 18, 2020 at 10:37 am - Reply

    A nice thing would be if u uploaded the whole code someehre

  7. Finnrock November 18, 2020 at 10:37 am - Reply

    Thank you so much. You're the first person to mention repaint(). I've been looking for almost a week to find that.

  8. 酷達CoolDDa November 18, 2020 at 10:37 am - Reply

    fake, this code works differently.

  9. Jiysea November 18, 2020 at 10:37 am - Reply

    How to animate with Colors and Timer?

  10. King Nauman November 18, 2020 at 10:37 am - Reply

    sir when i used to implement ActionListener interface, an error is shown saying the class like here you have tutorial is not abstract in order to implement interface, when i create class as abstract. I cant run the code coz i can't make object of it. what should i do please?

  11. Valerie November 18, 2020 at 10:37 am - Reply

    Thank you ,great explanation

  12. Adi MasterMind November 18, 2020 at 10:37 am - Reply

    Thanx !

  13. HONAREA GAMES November 18, 2020 at 10:37 am - Reply

    I have a Glitch in the animation , but I Use Ubuntu !! is there any solution Please ??

  14. Couch Potato November 18, 2020 at 10:37 am - Reply

    thanks

  15. tutoref November 18, 2020 at 10:37 am - Reply

    Simpler way even : https://youtu.be/_NEnhm9mgdE

  16. Edits MCU November 18, 2020 at 10:37 am - Reply

    is there a downloadable file for this?

  17. Nidal Al Saleh November 18, 2020 at 10:37 am - Reply

    how come when i write (public class tutorial extends JPanel implements ActionListener) always tell me that i have to make it abstract ? how can i disable it from becoming abstract ??

  18. tamil girl November 18, 2020 at 10:37 am - Reply

    IT is not moving

  19. Klhy November 18, 2020 at 10:37 am - Reply

    Your tutotrial is pretty easy to understand !
    Thanks!

  20. Evendra Kumar November 18, 2020 at 10:37 am - Reply

    could you please tell why this code
    doesnt run on bluej. It just show me "tutorial is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent)in java.awhich.ActionListener"

  21. Andrew Cheng November 18, 2020 at 10:37 am - Reply

    Thx for the tutorial!

  22. yonas tekle November 18, 2020 at 10:37 am - Reply

    i like it

  23. Christian D November 18, 2020 at 10:37 am - Reply

    good tutorial, but pplease zoom out a little – need to see the whole thing.

  24. Subzerus November 18, 2020 at 10:37 am - Reply

    And I thought my programming teachers were bad but this video must take the cake…

  25. Marc B. November 18, 2020 at 10:37 am - Reply

    My rectangle is lagging when moving, is it normal ?
    Here's the code guys:

    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;

    public class Tutorial extends JPanel implements ActionListener{
    Timer tm = new Timer(5, this); // 5 -> milliseconde, this -> ActionListener
    int x = 0, velX = 2;
    int y = 0, velY = 2;

    public Tutorial(){
    tm.start();
    }

    public void paintComponent(Graphics g){
    super.paintComponent(g);

    g.setColor(Color.RED);
    g.fillRect(x, y, 50, 30);

    // tm.start(); // not optimal
    }

    public void actionPerformed(ActionEvent e){
    if(x < 0 || x > 550)
    velX = -velX;

    if(y < 0 || y > 340)
    velY = -velY;

    y = y + velY;
    x = x + velX;
    repaint();

    }

    public static void main(String[] args) {
    Tutorial t = new Tutorial();
    JFrame jf = new JFrame();
    jf.setSize(600, 400);
    jf.setVisible(true);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setResizable(false);
    jf.add(t);
    }
    }

  26. Vivek sai kode November 18, 2020 at 10:37 am - Reply

    it much more simple than i thought!

  27. Fred Green November 18, 2020 at 10:37 am - Reply

    Instead of x = x + velX, you can use x += velX

  28. Mateo Obała November 18, 2020 at 10:37 am - Reply

    You're big man 😀 Thank you for this tutorials, greetings from Poland!

  29. crashonthehumble November 18, 2020 at 10:37 am - Reply

    thanks

  30. Folke Johansson November 18, 2020 at 10:37 am - Reply

    Simple, easy and good video. I've been looking around on how to animate and the other sources made it unnecessarily hard to understand.

  31. Malvin Bhatta November 18, 2020 at 10:37 am - Reply
  32. someone November 18, 2020 at 10:37 am - Reply

    How do you move a rect with 2 clicks?

  33. linker tab November 18, 2020 at 10:37 am - Reply

    How to add another Rectangle > >? ? Is it possible Adding another Rectangle ??

  34. Ina Cernisenco November 18, 2020 at 10:37 am - Reply

    +10

  35. Da_ K8Gamer November 18, 2020 at 10:37 am - Reply

    next time try to make the program from the begining………

  36. CodedGoat ;3 November 18, 2020 at 10:37 am - Reply

    What if I wanted what was drawn before to stay on the screen and for the screen NOT to be cleared?

  37. Alvin Zheng November 18, 2020 at 10:37 am - Reply

    Why it not work for me and it still says that the Tutorial is wrong and it has a red underline

  38. Michaelene King November 18, 2020 at 10:37 am - Reply

    Awesome tutorial. Thanks a million.

  39. Gunsong1 November 18, 2020 at 10:37 am - Reply

    good video. 2 tips though.

    1 if people don't know what interface implementation means, then they are not ready for animation programming, no need going through what implements means in what is supposed to be an intermediate subject.

    2 The way you "moved" the X over in the Y slot and said "just imagine that it is a Y variable", just makes your instructions harder to understand, as well as making your code look less actual implementation of this functionality.
    it took you more effort explaining your changes, than just adding the Y and velY would have been.

  40. Double H November 18, 2020 at 10:37 am - Reply

    Dude I have tried it but it doesn't move it paints to the infinity instead of moving

  41. BucioR102 November 18, 2020 at 10:37 am - Reply

    Good tutorial, but how to add TWO moving rectangles to one JFrame? I tried it, and second rect, is overwritting the first one. I tried using JPanel but it doesn't work 🙁 Or i'm doing something wrong 🙁

  42. aerro November 18, 2020 at 10:37 am - Reply

    What do you use to record?

Leave A Comment

*