Develop a Java Application program that draws a visual scene in the graphical output window. Your application must declare, instantiate and draw at least TWO (2) objects from each of TWO (2) different classes that represent visual objects (in other words, the classes must have adraw
method that can be called from theMUPanel
class). One of the classes will use the drawing methods of the Graphics class to display a Logo that you develop, and the other class will draw your initials made up of the shapes that can be drawn using the Graphics class methods. Each Logo object and each Initials object must be drawn in a different screen location. Details of this assignment and links to several example output screens appear below.
In effect, this assignment is quite similar to the Boat lab that we've worked on recently; with the requirement that two different-looking classes are written by the student, and at least two objects from each of the classes is drawn in different locations on the screen.
Create an application called PA1
(no spaces in the name, so PA1,
not PA 1). It should
have the classes MUPanel
, Initials
and Logo
in the files MUPanel.java, Initials.java and Logo.java,
respectively. To get started, you can use the MUPanel.java file
from previous labs you've worked on in Java (Lab1, for example), and you can
right-click on the following links and save the file in the src folder
of your PA1 project:
Initials
and
Logo
to names that are more meaningful for your project if you wish.
In the MUPanel
class, there should be two private data members (aka
properties) of type Initials
and two private data members of type
Logo
. They should be instantiated inside of the
MUPanel
constructor, and in the paintComponent
method
each of these objects should be "asked" to draw themselves, by calling their
draw
method.
The Initials
class and the Logo
class each should have
data members of type Integer
called anchorX
and
anchorY
. They may have other data members, too, as seen in
the sample Logo.java file you copied earlier. If you aren't going to use
some of the data members in the given code, you should delete them from the file
to keep your program as simple as possible.
The Initials
class and the Logo
class each need a
constructor method to initialize all data members.
The Initials
class and the Logo
class each need a
draw
method that accepts a parameter of type Graphics
.
All drawing done by the draw
method of the Initials
class
should be relative to one fixed point referenced by the anchorX
and
anchorY
data members. For instance you might use something like
g.drawRect(anchorX + 25, anchorY + 50, width, height);
rather than something like
g.drawRect(125, 250, width, height);
Similarly, the draw
method of the Logo
class should also
draw everything relative to one fixed point referenced by the anchorX
and anchorY
data members.
The draw
method of the Initials
class must use various
drawing methods of the Graphics
class to draw the three initials of
your name in some decorative style without using drawString
. You
may use your initials or your first name. (If you use your first name, the class
should be called FirstName
instead of Initials
.)
The draw
method of the Logo
class draws some kind of personal logo or
some kind of scene relating to a favorite hobby, sport or interest of yours.
You must use at least four different drawing colors, and at least four different drawing
methods of the Graphics
class (not counting setColor
). For
example drawRect
, fillRect
, drawOval
,
fillOval
, drawArc
, and/or fillArc
.
Note: You CANNOT use g.drawString
to cause your intitals to be printed on the
screen in the Initials
class — you must create the initials from basic shapes
like rectangles, ovals and arcs. However, you can use g.drawString
to draw some text in the Logo
class. See the last example below (the BOE
example), where
g.drawString
was used to print the name of the soft drink on each of the
bottles.
DO NOT use any of the shape-drawing or shape-filling methods of the Graphics
class
in the paintComponent
method of the MUPanel class. All drawing must be
done in the draw
methods of the Logo class and the Initials class.
Look here for some helpful hints.
This assignment includes the requirement to add at least two extra visual features over and above the base requirements that make the output of the program more fun, interesting, or surprising. Use your creativity and have fun with your drawings! Here are some suggestions for things you could do as enhancements:You must document your enhancements by adding comment lines at the top of your program in MUPanel.java after your CSC 120, name, etc, comments. Your comments should explain what you did for your enhancements.
- One possible enhancement would be to define your own colors (in addition to the standard ones that are part of the
Color
class). To do this, you can use the following method call:where the three parameters shown above represent the intensities of the red, green, and blue components of your chosen color, respectively. Each parameter must be an integer number between 0 and 255. How do you know the three primary color components of some shade you want to use (such as turquoise)? Visit the VisiBone Color Code Page to choose a color (the numbers shown diagaonally in each box give the red, green and blue values you should use when creating a new Color, in order from top-left to bottom-right). As an example, to draw using a light shade of yellow, use the following Java method call:g.setColor( new Color( red, green, blue) );
g.setColor( new Color( 255, 255, 153 ) );
- You could define an additional class or two to be other logo(s) that are displayed on screen along with your
Logo
andInitials
objects as an enhancement.
- Another possible enhancement could be using an irregular polygon (see the Polygon Demo page).
Every Java program written in the Department of Computer Science and Information Systems must follow the Department's documentation and style guidelines in order to obtain full credit. Click on THIS LINK to see a list of requirements for programming style in CSC 120.
When you have completed your NetBeans project for PA1 (including the comment header at the top of the MUPanel.java file with your name, etc.), use File Explorer to make a .zip file of the PA1 folder in your H:\CSC120\Java folder so that the file is named PA1.zip. Then upload that file to the PA1 dropbox in D2L.
PA1 Grading Rubric