Java Reference
In-Depth Information
10 Your School Logo
Companies sometimes use a splash screen on the Web to give the user something
to look at while the longer, graphic intensive Web page downloads. Write a
splash screen applet that displays the name of your company or school, the
address, the Web address, and your school's logo. Ask your instructor for the
location of the graphic file. Position the lines using the g.drawString() method
with the x and y coordinates. Position the graphic beside the text. Compile and
run the applet using TextPad. Then run the applet using a browser such as
Internet Explorer or Netscape by typing the path and file name of the HTML file
in the browser's Address text box. Compare the two results. Print both the source
code for the applet and the HTML file.
11 Creating a Splash Screen
In preparation for future Java programs, create a Java program, called Center,
that displays an opening screen with text information about your program cen-
tered in the middle of the screen. Include the name of your program, your name,
your instructor's name, the date, and any other necessary information. When
maximized, the command prompt window displays approximately 25 lines that
are 80 characters across. To center vertically, divide the number of lines of text
into 25 (dropping any remainder) to determine how many blank lines (\n) to
insert before each text line. To center horizontally, count the characters in the
line of text, divide that by 2 (dropping any remainder), and then subtract that
from 40 to determine how many spaces you should indent from the left margin.
Remember that each escape character (\t) moves the text approximately eight
characters to the right. Use the SPACEBAR to insert fewer than eight spaces. Com-
pile and execute your program. Save your program on the Data Disk.
J ava 2
J ava 2
v 5 . 0
12 Creating New Colors
v 5 . 0
Use the Java API (http://java.sun.com/j2se/1.5.0/docs/api) to research possible
colors for use with applets. When the API displays, click the java.awt package.
Then click the class, Color. Look at the Field Summary table for possible colors.
Then look at the Method Summary table for ways to change those colors. Write
an applet that uses some of the methods you found to set both the background
and foreground colors in an applet. If necessary, use the Java API Index at the
top of the Web page to look up and review the syntax for the setBackground()
and setForeground() methods.
Search WWH ::




Custom Search