A04
Due Date:
Friday, 5 February 2021
File(s) to be submitted:
FlagOne.java, FlagTwo.java, FlagThree.java
Sample Output:
SampleOutput.html
SUBMIT
/
Check
More Fun with Flags (GUIs and Inheritance)
Summary
Create three JPanel flags
and use the FlagFrame class provided
to display them.
FlagFrame.java
The first flag may be just stripes
(horizontal or vertical),
but the other two must be more interesting.
I have provided two example JPanel flags:
You can see the resulting windows in the sample output.
In order to make sure your code runs when submitted,
name the flag classes:
- FlagOne
- FlagTwo
- FlagThree
Do not name them after the countries!
Details
The class FlagFrame
represents a GUI designed to hold a flag image.
You need to put that class into your A04 project,
but don't change it
(except you may change or delete the package command).
Your task in this assignment is to create three classes
that extend JPanel
such that each one draws a flag.
In order to do that,
your class needs to:
-
Have a constructor that sets the preferred width and height of the flag
and sets the name of the flag:
-
Implement the paintComponent(Graphics g) method.
This method uses methods from the class Graphics
to draw the flag itself.
-
Have a main method that creates and shows
a FlagFrame object.
The FlagFrame constructor
needs to be given the flag object you've designed.
See the sample flags for examples of the above.
Notes
For the constructor:
For paintComponent,
I would like you to stick to the following methods:
- setColor(colour)
- fillRect(across, down, width, height)
- fillOval(across, down, width, height)
- fillArc(across, down, width, height, start, distance)
- fillPolygon(acrosses, downs, numCorners)
- fillPolygon(aPolygon)
In each of those methods:
- colour is a java.awt.Color
- across is an int saying how far across the flag
the "left edge" of the object is
- down is an int saying how far down the flag
the "top edge" of the object is
- width is an int giving the left-to-right size of the object
- height is an int giving the top-to-bottom size of the object
- start is an angle (0 means straight out to the right,
90 is straight up, and -90 is straight down)
- distance is another angle, with positive indicating
counter-clockwise direction
- acrosses and downs are int arrays of the same length
representing how far across the flag and down the flag
each corner of the polygon is
- numCorners says how many corners the polygon has
- aPolygon is a Polygon object
To draw in colour,
you need to set the colour just before you start drawing the objects.
Note that later objects are drawn over earlier objects,
a fact I used in both the sample flags
to colour in the central stripe.
I made the whole flag the colour of the central stripe,
then added to other stripes on top of that colour.
If you're clever,
you can use that fact to create a crescent in your flag
by drawing one oval on top of another.
Grading Outline
Your assignment will be graded out of 100.
-
Files with the wrong name will be penalized 10 points.
-
Code that does not compile will be penalized 10 points
plus 5 points for each line that needs to be fixed.
-
Up to 30 points may be deducted for code
that does not meet the standard requirements
described in the
rules for submissions
and the
style rules.
-
Up to 30 points may be deducted for code
that does not follow the design described above
and the general good design principles.
-
Up to 100 points may be deducted for code
that does not perform properly.
Yes, that is well over 100 points of possible deductions.
Doing half the job is not going to get you have the credit.
You need to do good work as a matter of course;
only excellent work will get full credit.
SUBMIT
/
Check