|
| 1 | +******************************************************************************* |
| 2 | +* Project: 1-Animated Marshmallow |
| 3 | +* Class: CS 121 section 2 |
| 4 | +* Date: September 23, 2014 |
| 5 | +* Name: Sami Stoodent |
| 6 | +******************************************************************************* |
| 7 | + |
| 8 | +PROJECT OVERVIEW: |
| 9 | + |
| 10 | +This Java application displays an animated marshmallow with features based on |
| 11 | +user input specifying sponginess, color, sugar density, and burn resistance. |
| 12 | + |
| 13 | + |
| 14 | +INCLUDED FILES: |
| 15 | + |
| 16 | + * README - this file |
| 17 | + * Marshmallow.java - the main source code |
| 18 | + |
| 19 | + |
| 20 | +BUILDING AND RUNNING: |
| 21 | + |
| 22 | +All project files should be in the same directory. |
| 23 | + |
| 24 | +From the directory containing the .java source code, compile the program: |
| 25 | + $ javac Marshmallow.java |
| 26 | + |
| 27 | +Run the program from the directory containing Marshmallow.class: |
| 28 | + $ java Marshmallow |
| 29 | + |
| 30 | +You will be prompted for integer values representing distance to the fire, |
| 31 | +fire intensity, marshmallow burn resistance, and marshmallow sugar density. |
| 32 | + |
| 33 | + |
| 34 | +PROJECT DESIGN: |
| 35 | + |
| 36 | +The Marshmallow class extends the JPanel class, so it has all of the |
| 37 | +properties and methods of a JPanel - this class basically just overwrites |
| 38 | +the JPanel paintComponent() method and includes a Timer and ActionListener |
| 39 | +to update and refresh the panel by periodically calling paintComponent() |
| 40 | +indirectly via the repaint() method. Because main() creates the JFrame and |
| 41 | +an instance of Marshmallow, this class is self-contained and there is no |
| 42 | +separate driver class. |
| 43 | + |
| 44 | +After JPanel, the classes that were the focal points of this program were |
| 45 | +the Timer and Graphics classes. The Timer code was given to us. Most of |
| 46 | +the work for this program centered around the Graphics class and its many |
| 47 | +draw and fill methods. |
| 48 | + |
| 49 | +All graphic elements are drawn relative to a single anchor point for ease |
| 50 | +of relocating as the canvas is resized. The marshmallow is centered in the |
| 51 | +view and sized so that it occupies 50% of the lesser of the width and height. |
| 52 | +Text output is also resized to ensure it fits within the view and doesn't |
| 53 | +cover the marshmallow. |
| 54 | + |
| 55 | +Each of the user input parameters uses a separate input dialog box. It |
| 56 | +works, but it seems clunky. I think it would be better if there was one form |
| 57 | +at the beginning with all the choices, but I'm not sure how to do something |
| 58 | +like that yet. |
| 59 | + |
| 60 | +I originally intended to make the animation refresh rate adjustable, but ran |
| 61 | +out of time. The hardcoded refresh rate looks good on my local machine, but |
| 62 | +it's too fast when viewing the animation over a remote connection, so this |
| 63 | +feature would be a good addition to the project. |
| 64 | + |
| 65 | + |
| 66 | +PROJECT DEVELOPMENT AND TESTING DISCUSSION: |
| 67 | + |
| 68 | +When I realized my paintComponent() method was getting really long and hard to |
| 69 | +read, I broke out each graphical element into its own private method. The hard |
| 70 | +part of that was figuring out that I needed to pass in the Graphics object to |
| 71 | +each method, but it worked well after I did that. It also helped to read about |
| 72 | +the Graphics class in the Java API, to learn how to use the different draw |
| 73 | +methods. |
| 74 | + |
| 75 | +I tested values from 0 to 20 for each of the input parameters, but I found that |
| 76 | +values greater than 20 cause the program to freeze up. I don't know how to |
| 77 | +restrict input values, yet, but that would be a good feature to add. I added |
| 78 | +a warning to the input dialog, but there's nothing to stop users from adding |
| 79 | +values over 20. |
| 80 | + |
| 81 | +I tried running the program remotely over SSH with X, but my connection wasn't |
| 82 | +fast enough to see the animation very well and there were several times the |
| 83 | +dialog boxes for my input prompts showed up behind the main window. When I |
| 84 | +came into the lab and ran it, however, everything looked good and worked just |
| 85 | +like it did when I ran it locally on my own computer. |
| 86 | + |
| 87 | +The starting file for the project had a window size of 200 x 500, but I found |
| 88 | +that the text was too small to read unless the height was at least 300, so I |
| 89 | +ended up with minimum dimensions of 300 x 500. It looks best, though, even |
| 90 | +bigger. I recommend 400 x 600. |
| 91 | + |
| 92 | +This project was challenging at first, but it was fun once I got the hang of |
| 93 | +it and I feel like I learned a lot about graphics in Java. |
| 94 | + |
| 95 | + |
| 96 | +EXTRA CREDIT: |
| 97 | + |
| 98 | +I added the flame animation and screaming sound effect when the marshmallow |
| 99 | +overheats. You can see it when sugar density is > 10 and burn resistance is |
| 100 | +< 15. |
0 commit comments