The assignment for this lab is to create a project that produces an applet that looks something like this:
.mcp
. Then click OK.
TrivialApplet.html
,
TrivialAppletDebug.html
, and TrivialApplet.java
. Remove these files from
your project by dragging them from the project window to the trash. Note that deleting these files
from the project does not automatically delete them from the project folder. If you want to delete
them from the folder, double-click on the folder to open it, and then drag the files into the trash.
New Text File
from the File
menu. A new untitled
file will open.
You need to create two files: the HTML file that specifies which class to run and the JAVA file.
Your HTML file can have any name and (for this project) it will look like this:
<TITLE> Rainy Day Applet </TITLE>
<applet codebase = "Java Classes" code = "RainyDay.class" width = 400, height = 400>
</applet>
Type this code into the new file and save it in the project folder. You
can give it any name with the extension .html
.
RainyDay.java
and save it in the
project folder. The name of this file must be the same as the name of the class
that it defines (only with the .java
extension), and in our case the class
is RainyDay.class
, as specified in the HTML
file above.
RainyDay.java
into the project window in the folder Sources. A window
will pop up asking you to confirm that you are adding the files to the project's targets.
RainyDay.java
. Recall that we want
the applet to look something like this:
java.awt.*
and java.applet.Applet
.
RainyDay.class
, since this
is the class invoked in the HTML file. Since you are writing a program that runs as an applet,
the class should extend the class Applet.
paint
of the class Applet.
drawString
of the Graphics package. Click
here for the description of the method.
setColor()
you
use setFont
(see the Graphics contract).
Yes, but what do you set the font to? You need to create a new Font
object.
You can read about the
Font
constructor in the Font contract.
The Font contract is given in your textbok, or read the
font contract in
Java online documentation. To give you a hint, the font used in the example has the name
"Serif", its style is Font.BOLD
, and the size is 20. Please feel free to experiment with
different font names, styles, and sizes! You can also change the color of the text by setting the
color of the Graphics object.
RainyDay
to draw an umbrella with the
specified size, colors, and location, and invoke this method 3 times with the appropriate parameters.
You can do it
either way, or in any other way, as long as the resulting picture looks like the one above.
drawArc()
and fillArc()
of the class Graphics.
You can read about these methods in the
Graphics contract.
You need to read the description carefully, but to figure out how the methods work
you might need to experiment with different parameters. It's OK if your first picture does not look
like the shape of
an umbrella. Keep on trying! When you get the correct shape, try adding color: first fill the entire
shape with one color, then fill one half with one color, and the other half with the other color. Then
add the middle part of the umbrella, and so on.
And the usual, but still important, advice:
Only this way you know what works and what doesn't.