1 / 4

Animation in Java

Animation in Java. AnimationDemo. Checkout AnimationDemo from your repository. Run it. Examine its code as you go through the following slides. AnimationDemo uses a Model-View-Controller (MVC) architecture

jarvis
Download Presentation

Animation in Java

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 in Java

  2. AnimationDemo • Checkout AnimationDemo from your repository. Run it. Examine its code as you go through the following slides. • AnimationDemo uses a Model-View-Controller (MVC) architecture • Model: “represents the information (the data) of the application and the business rules used to manipulate the data.” • In AnimationDemo, simply a number X that increases/decreases at each step of the simulation • View: provides a visual display of the model • In AnimationDemo, X is displayed as a point that moves right to indicate the passage of time and up/down to indicate X increasing/decreasing • Controller: coordinates the Model and View • In AnimationDemo, constructs and starts Threads for the Model and View

  3. UML class diagram for AnimationDemo Questions on structure of AnimationDemo?

  4. Key Concepts for Animation in Java Questions about Animation in Java? • Start a Thread that operates on the panel new Thread(panel).start(); • Find this statement in the Controller class • This means that the panel is Runnable, i.e., has a run method • The run method runs once, when the Thread starts • For animation, the run method should contain an infinite loop that repeatedly asks the panel to repaint itself • Find the run method in the View class of AnimationDemo • Note how the frame rate is controlled by Thread.sleep • Calls to repaint cause paintComponent to run • paintComponent should draw the current state of the animation • Find the paintComponent method in the View class of AnimationDemo • Note where it gets its data from the Model AnimationDemo chose to have separate animations (Threads) for the Model and the View, to separate Model from View. Alternative: use a single Thread for both.

More Related