Cartoon 

Cartoon Cartoon Design Questions Due Date: 2:00 pm Sunday, October 12th Help Session: 6:00pm Sunday, October 12th in Barus and Holley 166 Cartoon Early Due Date: 11:59pm Thursday, October 16th Cartoon On­Time Due Date: 10:00pm Saturday, October 18th
Cartoon Late Due Date: 11:59pm Monday, October 20st To run the demo, type in a shell: cs015_runDemo Cartoon
To run a snazzy demo, type in a shell: cs015_runSnazzyDemo Cartoon
To begin coding Cartoon, type in a shell: cs015_install Cartoon
Silly Premise Janice is having an art show next week. Since Janice is a loser, she needs to have the best art in order to get people to come. She has contacted the CS15s with an interesting request. She is currently recruiting the top cartoonists to help make her show less lame, so now is your chance to show off your skills at drawing cartoons in Swing! Your cartoon doesn’t have to be Mean Girls themed. Janice and the TAs are simply looking for a sample of your animated work to see what CS15 students can do (and to get people to come to the Art Show instead of Cady’s party). Okay, Art Freaks. Take that deli meat off your face (no food in the Sunlab), and start early, start today, start yesterday! New Concepts Covered ●
●
●
●
●
●
GUIs (Graphical User Interfaces) Graphical Containment Layout Management Complex association and sharing references Events and Listening Swing and java.awt Assignment Specifications 1 Here's your chance to be creative with Swing. While we require that you implement some standard base functionality, we also want you to be creative with this. **This means you may not simply make the alien from the lecture slides.** The assignment specification is simple: create a graphical user interface that accomplishes a minor task, and uses at least 2 different shapes. After you have the base specs working, use your imagination, artistic ability (let's see it, you VA majors!), and programming skill to make something that wows your friends. Think moving shapes, changing colors, and 3­D rotating fractal landscapes. To provide some direction we require the following elements as base functionality. Before you even start thinking about extensions to this assignment, make sure you have the following: ● A composite shape. That is, a class that contains more than one instance of a Shape subclass. You can either use the classes we provided or make your own. ● A DrawingPanel
● A JButton that quits your program properly. This button will need an ActionListener that calls System.exit(0), which exits the program. ● A javax.swing.Timer that animates your Cartoon in some way. ● A javax.swing.JLabel with text that changes based on something in your Cartoon (for example, based on the changing location of your shape). ● Appropriate javax.swing.JPanels with appropriate java.awt.LayoutManager(s) so that your components line up nicely within your GUI. ● Use at least two different shapes By creating a GUI we hope that you will get a solid grasp of Swing. However, we don't want to squash your creativity by dictating the exact GUI layout. Nevertheless, if you are lacking inspiration, you may emulate the layout of one of the demos. In any case, be sure to explain why you arranged your GUI the way that you did in your comments. Programming Tips This is the first of the projects using Swing. Swing is designed to be used for a wide variety of applications and thus has many tools that you can use for this and later projects. If you want more information than the lecture slides provide, you can go to the online tutorial made by Sun on http://java.sun.com/docs/books/tutorial/uiswing. It’s a little spread out and hard to follow in some places, but it covers a wide range of topics. However, we give you more than enough info in the lecture slides to complete this assignment. 2 Because you'll be doing this in Swing, the stencil code we give you consists of just an App that takes care of the mainline. It’s your job to create a javax.swing.JFrame and design your program appropriately. Make sure to call pack() on your frame at the end of the constructor to properly size it and setVisible(true) to show the frame. For Cartoon, start by just getting your JFrame to appear. Then, we suggest that you take care of all the GUI components, for example, a panel to hold your labels, buttons, etc. – the sky’s the limit! Then take care of your graphics. It is a very good idea to code this assignment incrementally, making sure it compiles and does what you expect at each step. Note that to import the Shape package, you should call import cs015.prj.Shape.*;
To use the package, simply put Shape.<class name>. For example: Shape.EllipseShape sun = new Shape.EllipseShape();
sun.setColor(java.awt.Color.YELLOW); //etc… Possible Bells and Whistles If you want to add extra credit to your assignment, take a look at the snazzy demos. Additionally, here are some possible ideas: ● Pop up new windows that allow the user to choose what is shown in your DrawingPanel. ● Include other Swing elements, like JSliders, JCheckBoxes, JRadioButtons, or something else to interact with your Cartoon in even more ways. ● Find a way to have key or mouse interactions! Talk to a TA at hours if you have questions about how to implement this. Remember that you should make sure that you have a fully functional program before working on extra credit. If you have any other ideas for extensions, you may want to talk to a TA before attempting to implement it. Remember, from the Standard Operating Procedure: “[Extra credit is] to be done only after the original assignment is completed in full. You must include full documentation of your program's additional functionality in the program header. In other words, if everything is working right, extensions will give your grade a boost, but if you did not do part of the assignment, the extensions will be worth nothing. This also means that extra credit will not be assessed for your project if you hand in a project late. This is not arbitrary; most extensions, while requiring extra work, do not teach new concepts.” 3 Handin Info
The early date is at 11:59pm Thursday, October 16th The on time date is at 10:00pm Saturday, October 18th The late date is at 11:59pm Monday, October 20st To hand in Cartoon, type into a shell: cs015_handin Cartoon As usual, your program must be fully commented. This means we are expecting to see header comments for every class and in­line comments on any methods you write, but you do not need to comment saying something like “//here I am declaring a private instance variable of type JPanel” – we trust you know what you’re doing. The Shape package As shown in Lecture 10, the TAs have written a Shape package for you. Described below are some Shape classes and methods you might want to use for your Cartoon. (Also look at Lecture 10 Graphics Part 2 for more information on how to use Shape.) Be sure to import cs015.prj.Shape.*
Name: cs015.prj.Shape.Shape
Purpose: This is an abstract class we’ve provided that takes some java.awt.geom.RectangularShape in its constructor and adds some additional functionality. If you decide to create your own shape, you should extend this class. Methods: Shape(java.awt.geom.RectangularShape s)
Stores a java.awt.geom.RectangularShape as an instance variable, which can be accessed and mutated via methods in the Shape class. See the Graphics Part 2 lecture for a list of Shape’s accessors and mutators Name: cs015.prj.Shape.RectangleShape Purpose: RectangleShape extends Shape and passes a java.awt.geom.Rectangle2D.double in its call to super( ) Constructor: 4 RectangleShape()
Name: cs015.prj.Shape.EllipseShape Purpose: EllipseShape extends Shape and passes a java.awt.geom.Ellipse2D.double in its call to super( ) Constructor: EllipseShape() A few important Swing classes Described below are some of the Swing classes that you will want to use in your Cartoon program. Be sure you have looked over the Graphics lectures. Note that these classes are no longer part of our support code; they are classes built into Java and thoroughly documented in the Javadocs. Make sure you read through the Javadocs carefully for each of these classes to see how they are used and what else you can do with them. You can find the Javadocs Swing documentation at http://docs.oracle.com/javase/7/docs/api/javax/swing/package­summary.html Name: javax.swing.JButton
Purpose: This is an example of one of the buttons you’ll need to use in your GUI. The quit button should be a JButton. Methods: public void addActionListener(ActionListener l) Registers the specified ActionListener with this component. _______________________________________________________________________
Name: javax.swing.Timer
Purpose: This class models a timer that “ticks,” or fires an ActionEvent, at pre­defined intervals. This will notify an ActionListener, which can send messages to your other objects. This is how you will be able to animate your Cartoon. 5 Methods: javax.swing.Timer(int delay, ActionListener listener)
Constructs a timer. The delay parameter represents how many milliseconds the timer will wait between “ticks.” The listener parameter should be an instance of a class that implements the java.awt.event.ActionListener interface, just like the one you added to your JButton. At every tick, the Timer will automatically call the listener's actionPerformed(java.awt.event.ActionEvent e) method, which you'll have to fill in. void start()
Starts the timer. Until you call this method, the timer will not send any action events to the listener. The timer will send an execute actionPerformed(java.awt.event.ActionEvent e) every time it ticks from the moment start() is called until the moment stop() is called. void stop()
Stops the timer. You can also check out the Javadocs to find out about the Timer's other methods at http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.html __________________________________________________________________________ Name: javax.swing.JLabel
Purpose: This class models a text string that will show up in a GUI. You can add a label to a JPanel just like a button! Methods: javax.swing.JLabel(String text)
Constructs the label and displaying the parameter as text. void setText(String text)
Changes the string displayed by the label to that specified by the parameter. _____________________________________________________________________
_ For more info on useful classes, look in the Javadocs for: java.awt.FlowLayout
6 java.awt.GridLayout
java.awt.BorderLayout
java.awt.event.ActionListener
java.awt.event.ActionEvent
javax.swing.event.ChangeListener
javax.swing.event.ChangeEvent
7