Java Reference
In-Depth Information
Write the Interface Source Code
Start by writing the .java file for an interface named Paintable. The interface
will represent any object that can be painted onscreen. It will contain a single
method named paint().
Type in the Paintable interface shown in Figure 10.1.
Compile the Interface
Save the source code file in a new directory named c:\interfaces\display. Cre-
ate this directory, and save the file there as Paintable.java. Interfaces are com-
piled the same way as classes, using the javac compiler. Because you already
created the \display directory, and Paintable.java is saved in that directory,
you do not need to use the -d flag. You can compile it using the command line
shown in Figure 10.2.
You should see a new file named Paintable.class in the \display folder. The
display.Paintable interface is now ready to be implemented by a class, which
we will do next.
Figure 10.1
The Paintable interface is in the display package.
Figure 10.2
Compile the interface using the javac compiler.
Search WWH ::




Custom Search