Java Reference
In-Depth Information
5 Formatting Output Using Escape Characters (continued)
1. Start TextPad.
2. Save the program as Java source code with the file name MIC on your Data
Disk.
3. Type block comments to include your name, the date, the program's name,
the course number, and the program's purpose. Press the TA B key as needed
to align the comments. Remember to use /* to begin the block comment and
*/ to end it.
4. Enter the code from Figure 2-77 in the TextPad window, using the escape
code sequence \t as indicated. Hint: Eleven spaces separate the Ms in line 5;
each successive line has 2 less spaces.
1 public
class MIC
2 {
3
public
static
void main ( String []
args )
4
{
5
System . out . println ( "\tMM
MM\tIIIIIIIIIIIII\t
CCCCCCCC ) ;
6
System . out . println ( "\tM M
M M\t
I
\tCC" ) ;
7
System . out . println ( "\tM M
M M\t
I
\tCC" ) ;
8
//Add new code here
9
}
10 }
FIGURE 2-77
5. Add three or four more lines of code to complete the school's initials.
6. Compile your program.
7. If no compilation errors occur, run the program.
8. Using TextPad, print a copy of the source code.
6 Creating an Applet with a Background Color
In preparation for creating your own personal Web page, you would like to view
some possible background colors that will be easy to read with black text. You
decide to write a Java applet that displays black words on a colored background.
You will use the setBackground() method, which accepts a color argument in
applets.
1. Start TextPad. Save the file as Java source code with the file name
MyColorApplet.
2. Type a block header with the information about you and the assignment.
3. Import the java.awt.* and java.applet.* packages.
4. Write the class header for MyColorApplet. Remember to extend the Applet
class. Include an opening brace for the class.
5. Write a method header for the paint() method. Include an opening brace for
the method.
Search WWH ::




Custom Search