Write a program that reads in a text file and animates the lines together from the bottom to the top of the screen, similar to the movie Star Wars.
This graphics program can be modeled by imagining each line of the text file as a single GLabel. We want to put all of these GLabels on the screen, and then animate them up the screen all at the same time. Try approaching the following steps to do this:
- Add the background image (hint: use
setSize to resize it)
- Read in the text file
readFile, which takes a filename as a parameter and returns an ArrayList of the lines in the file. Like this:
ArrayList<String> lines = readFile("myfile.txt");
- Place the labels bellow the screen. The first label should initially be LABEL_PADDING pixels bellow the screen, and each label should be
LABEL_PADDING further down.
Some Strings are empty (
"") which is fine. This will add spacing.
- Animate the labels onscreen by moving all the labels up a small amount, then pausing, and then repeating.
- As a first step, load the ArrayList of lines from the file (test that this works)
- Make a GLabel for each line and place it in its initial position. You can pull the bottom corner of your graphics window to change the size of the screen and look for objects. Here is a figure of the initial position of the GLabels:
- Animate the GLabels
- Add a background and change the labels to be white