jaz
Posts: 4
Nickname: jaz
Registered: Oct, 2002
|
|
need help
|
Posted: Nov 11, 2002 5:00 PM
|
|
Advertisement
|
The program will consist of three classes, Demo, DemoPanel, and Bar. Demo will be be a subclass of
JFrame and DemoPanel a subclass of JPanel. Bar will be a subclass of Object only. All classes
will be in one package, with a name of your choice.
When the program starts, the Demo window will fill the top right quarter of the screen. This sizing and
positioning will be based on the current screen display mode, not on hard-coded constants. The window
title will be "Graphics Demonstration". An inner class will be used to handle window events.
When the program is initially displayed, it will:
Fill the top half of the window with three horizontal bars each covering the full width of the window
(see picture below). The bars will be of equal height. Each bar will have a different background color;
the colors can be in any order. Each bar will have a text string. The font size in points will be one-half
the bar height in pixels, i.e., you can assume one pixel = one point. The string will be centered
horizontally in the bar, and the baseline (vertical) position for the string will be the center of the bar.
Any font style can be used, and any text string can be used, but each text string must include the
letters g and h. (To make it easier to verify that the string is horizontally centered, you may want to
have each string contain a large number of characters.) The color of the text string should be such that
the string is readable given the bar background color.
Fill the bottom half of the window with the image indicated in class. A MediaTracker will be used
to load the image.
If the window is deiconified, the program will add a fourth bar to the top half of the window, if the
fourth bar does not already exist. This bar will be just like the other bars except it will have a different
text string and different colors.
If the window is moved or resized, the current bars (either 3 or 4 depending on whether the 4th bar has
been added) will be redisplayed such that they continue to cover the top half of the window. The bars
will continue to be of equal height, their colors will be maintained, the font size will continue to be half
the bar height, and the bar texts will continue to be centered horizontally and written vertically at the
center of the bar. The image will continue to fill the bottom half of the window. There must be no gaps
(empty pixel rows) between bars or between the bottom bar and the image.
The Demo class will have any fields required. Its only public methods will be the default constructor and
the main.
The DemoPanel class will any fields required and at least the following public method:
void paintComponent(Graphics g), which will paint the DemoPanel
The Bar class will encapsulate a bar. It will have all the fields required to define the colors and string
for a bar. The Bar class will be designed such that the state of a Bar object does not change after it is
constructed. Bar will have the following public object method plus any other methods required.
draw, that draws the bar. You must choose the parameters for this method.
|
|