ASCIImations in CS1/CS2

Niche: CS1 or CS2 course
Assumes:Fundamental programming skills in Java, including some simple GUI-building.
Covers: GUI design and construction, Java Timers and events.

For this assignment, you will design and implement a Java application that displays ASCIImations. An ASCIImation is a movie made up of individual frames, where each frame is a series of text lines containing ASCII-characters. Your application must be able to read in a movie from a file, with each frame separated by the divider "=====". A movie file should be able to end either with or without a divider. The sample movies bounce.txt and pirate.txt are provided as illustrations.

As part of your application, you should define a class that represents an ASCIImation. This class should provide the functionality to read and store a movie, and to produce the frames of the movie one at a time (in sequential order). For our purposes, we will assume that movies always run in a loop, so the first frame in the movie always follows the last.

In addition to your ASCIImation class, you will need to design and build a graphical user interface for displaying the movie. At a minimum, your GUI should allow the user to enter the file name for an ASCIImation, start the movie, and pause the movie. The user should be able to change the ASCIImation and view it without restarting the application. For example, a basic GUI might look like the following:

ASCII animation screenshot

Note that this is the minimum functionality that your GUI must provide. You are encouraged to explore the Java Swing libraries and implement additional functionality. Ideas might include adding a step button (for stepping one frame at a time), a slider to control the speed of the movie, a check box for turning looping on or off, and a pop-up menu for selecting files. Have fun with it.

In order to display the frames of the movie in sequence, you will probably want to make use of the java.util.Timer and java.util.TimerTask classes. Your GUI class will need to have a field of type Timer (for scheduling evenly-spaced threads to draw the frames) and an inner class that extends TimerTask to draw a single frame. For example:

    private Timer drawTimer;
    private class DrawAFrameTask extends TimerTask {
        public void run() {

At the point in the code where you want to start drawing the movie, you will need to call the schedule method on your Timer object to schedule the drawing tasks. This method takes as parameters a TimerTask, the number of milliseconds before the first task is to be executed, and the number of milliseconds between tasks (denoted here by the constant DELAY). For example:

    drawTimer.schedule(new DrawAFrameTask(), 0, DELAY); 

Review the documentation for the Timer class for additional functionality, including how to stop the Timer.

You must demonstrate good programming style when completing this assignment, including the appropriate use of Javadoc-style comments for all classes and methods. As part of this assignment, you must hand in an ASCIImation of your own design and construction. A prize will be awarded to the student with the most creative movie.