1 / 5

Animation

This guide explains the key concepts of animation in Java using threads and the Runnable interface. It covers the implementation of a custom thread class (MyThread) that facilitates smooth animations by utilizing the sleep method to control timing and the repaint method to update the graphical user interface (GUI). The tutorial also discusses the essential components of setting up a new thread in the main class and emphasizes the role of paintComponent for rendering graphics. Explore how to animate objects effectively while ensuring a responsive GUI.

hedy
Télécharger la présentation

Animation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Animation Albert Johnson Molly Richardson Andrew Kruth

  2. Concepts • Threads • Runnable interface • sleep() • GUIs • repaint() • paintComponent()

  3. Quick Thread Review • Class that implements Runnable • run() • try – catch • sleep() • class MyThread implements Runnable { • public MyThread(…..parameters…..){ • ……..Initialize class variables…… • } • public void run() { • for........ { • Stuff…………. • try { Thread.sleep(DELAY); } • catch(InterruptedException e) {} • }

  4. Quick Thread Review cont… • Main class that creates your Runnable object • public static void main (String args[]) { • …..set your initial values….. • MyThread thread = new MyThread(..parameters..); • Thread t = new Thread(thread); • Thread.start(t); • }

  5. The Animation Part • Animation = threads + GUIs. • Basic Ideas for animation: • paintComponent() • this is where your GUIs will be. • MyThread • run() • This is where you change your positions • sleep() – necessary to be able to see the animation • repaint()

More Related