- Using Visual J++ -

Chapter 6

Reviewing the Sample Code


In this chapter, you'll really use Visual J++! To fulfill this book's namesake, you'll be using Visual J++ by looking at the numerous samples that Microsoft supplies. Sit back while you view the samples; you won't yet understand everything about the code or tools that you use to execute the samples but that's okay. The goal of this chapter is to show you what Visual J++ can produce and to provide access to examples that activate your Web pages with applets.

This chapter works like a mini-reference chapter for Visual J++'s sample applets. The goal of this chapter is two-fold: The short-term goal is to show you what Visual J++ can do. The long-term goal is to provide descriptions of the sample files so that you can return to this chapter when learning a particular topic or command and find an example that is close to the code you want to write. You then can adapt the sample code to your own needs or get pointers from the professional samples that will help you complete your own applet.

Preparing for the Samples

Visual J++ does not automatically make the sample applets available for your immediate use, but you can easily prepare one or more samples. Generally, you'll follow these steps to activate a Visual J++ sample applet:

  1. Click the InfoView tab inside your Project Workspace window.
  2. Expand the Samples entry.
  3. Click the group of samples you want to select.
  4. Double-click the sample you want to see.
  5. Click the Help dialog box's command button to install the sample and its associated files. Accept all the directory defaults and remember the name of the sample's class file (found in the Help dialog box).
  6. Close the Help dialog box.
  7. Choose File, Open Workspace and select the sample's project file.
  8. Choose Build, Execute to build and run the sample.
  9. If Visual J++ asks for a class name, type you used in step #5.
  10. 10. Visual J++ starts your browser or applet view and displays the sample applet.

Visual J++ includes two sets of samples. The first set is a collection of applets from Sun Microsystems that have been around for a while and passed from Web site to Web site that demonstrate many of Java's language features. The second applet collection demonstrates several features unique to the Visual J++ implementation.

The following sections cover a few of the examples that come with Visual J++. I will cover a few of the neater examples that show some of Java's power features and functions.

The Animator Sample

The Animator sample displays animation. If you have an audio card, you should also hear sounds when you run the Animator applet. The Java language supports audio as well as graphics. When you start the Animator applet, you'll select from the following choices:

Figure 6.1 shows the Duke character waving to his fans.


FIG. 6.1

Watch Duke wave and tumble.

 
The cryptic information at the bottom of Duke's Animator screen will come in handy in chapter 7, "Reviewing Java's Nature," where you'll use that extra information to change the behavior of the samples. The information describes several values that control the applet's execution and once you learn to change these values, the applet's behavior will change.

The Arc Test Sample

Once you master the primitive graphic commands in chapter 14, "Adding Graphics," you'll want to explore some of the more advanced graphics commands. The Arc Test sample demonstrates advanced graphics programming techniques, using the arc drawing tools found in Visual J++. Figure 6.2 shows the Arc Test sample applet.


FIG. 6.2

Determine the arc angle and fill it in.

The Bar Chart Sample

Simple bar charts are easy to produce, which the Bar Chart sample applet demonstrates. Figure 6.3 shows the bar chart that appears when you execute the Bar Chart applet. Once you learn the graphics commands, you'll be able to create bar charts that show trends and data comparisons.


FIG. 6.3

Create colorful bar charts with Visual J++'s graphics.

The Blinking Text Sample

Visual J++ lets you create extremely active Web pages. You can even make your text jump around, which the Blinking Text sample applet demonstrates. When you run this sample, watch the screen's text characters change color and position.

The Bouncing Heads Sample

I'm not sure whose head is bouncing in figure 6.4, but the Bouncing Heads sample applet seems to have fun moving the heads around. As you can see, this applet demonstrates how you can load and animate graphic images on your screen.


FIG. 6.4

Can't this guy stay still?

The Card Test Sample

When you place controls on the applet screen, you'll use layouts similar to the Card Test sample applet's (see figure 6.5). The Card Test demonstrates how interactive your Web sites can become as you click the various numbered panels on-screen.


FIG. 6.5

Choose from five pre-defined layouts.

The Dithering Test Sample

To dither two or more colors is to determine how the colors combine to form new colors and transitional color patterns. The Dithering Test sample lets you see how colors change from one to another. By controlling the from and to colors, as well as the amount of Red/Green/Blue (RGB) valued combinations that you start with, you can see how your colors will blend in your own programs.

 
Obviously, you will not see the blue and red dithering in this book, but you will appreciate the colorful pattern if you run the Dithering Test sample.

When you begin to add graphics to your Visual J++ applets, as you'll do in chapter 14, you will learn about how RGB combinations affect your programs.

The Draw Test Sample

The Draw Test sample applet, shown in figure 6.6, lets you draw straight lines and crooked lines depending on whether you select Lines or Points from the drop-down list box. The applet demonstrates how to use the graphic commands to dynamically follow the user's drawing directions. When you want to change paint, select a different color from the bottom of the window.


FIG. 6.6

You call this art?

The Fractals Drawing Sample

A fractal is a special pattern that often appears in nature, mathematical, and scientific arenas. An entire spectrum of computer art sprang up when someone implemented fractal formulas to produce graphic fractal patterns on the screen. The computer's quick calculating speed makes the study of fractals simple.

If you load and execute the Fractals Drawing program, you will see a fractal shape appear. The initial fractal starts simple and then progresses to a more complex drawing. The fractal images come from advanced graphic methods combined with extremely complex math formulas; as you can see, the Java language is rich in both graphics and mathematical power.


FIG. 6.7

The fractal appears as your computer computes the next fractal pattern.

The Graphics Test Sample

You'll learn in chapter 14 about the Java language's primitive graphics commands that you can combine to draw any shape you need. The Graphics Test lets you view the primitive shapes and see how the various color combinations add eye-catching appeal to the simple graphics drawings.

When you run the sample, you'll be able to select the shape you want to see or click the Next and Previous command buttons to display the next or previous shape in the list.

The Graph Layout Sample

The sample applet gives you a chance to see the following various network topologies and the stress points that can be put on various hookups. The following shows you the choices that you can select from:

This sample applet is demonstrating graphics layouts that are available in the Java language. Figure 6.8 shows an example of the Web combination.


FIG. 6.8

Dynamic graphic connections move on the screen.

The ImageMap Sample

The ImageMap sample demonstrates Java's ability to provide shaped filters over graphic images. When you load and run the applet, you'll see a huge picture of Jim Graham (you know this from the Jim.graham.gif file name), as figure 6.9 shows, over which you can move your mouse. If you move your mouse over a graphic hot spot, the hot spot's filtered shape appears.


FIG. 6.9

Move your cursor over the image areas to display a filter.

The Image Test Sample

The Image Test sample demonstrates graphics movement (see figure 6.10). Click either of the two images and press your arrow keys or the PgUp and PgDown keys to move and resize the images. Shift+PgUp and Shift+PgDown changes the current shape's alpha (the amount of graphics purity).


FIG. 6.10

Move and resize graphic images.

The Jumpingbox Sample

The Jumpingbox sample applet lets you play a game of hand, eye, and mouse coordination. The small box runs as you chase the box with your mouse. If you are fast enough to click your mouse pointer while it's inside the box, you'll be rewarded with a message at the bottom of the screen. If you can click the box two or more times, you'll quickly see the message, You're on a roll! but you have to look fast!

The Nervous Text Sample

The Nervous Text sample applet demonstrates Java's ability to move text. Graphics are not the only screen elements you can manipulate in random patterns. As you view the Nervous Text applet's text, you'll feel as if the text has seen one too many compiles.

The Scrolling Images Sample

The Scrolling Images sample displays a scrolling list of faces across the top of your applet's window (see figure 6.11). The scrolling is smooth and you can see that graphic image files are as easy to manipulate as text and shapes. You'll think you're looking at a criminal lineup!


FIG. 6.11

Scrolling faces across your screen.

The Spread Sheet Sample

The Spread Sheet sample applet actually contains a simple spreadsheet with values and formulas that you can change (see figure 6.12). If you want to change a value, click the appropriate cell and press Backspace to erase the value or type additional digits to add to the number. If you precede a number with "v" (for value), the spreadsheet treats the cell as a value but if you precede a cell's formula with "f," you can enter a formula and use the cell's coordinates (such as "vB2+A1") to reference values. You will be able to learn how Java's interactive abilities let Internet users can dynamically manipulate Web page data.


FIG. 6.12

Calculate a small spreadsheet.

The TicTacToe Sample

Test your ticktacktoe skills against Visual J++ by executing the TicTacToe sample applet shown in figure 6.13. Here's a hint: take the center square!


FIG. 6.13

Play TicTacToe and win, lose, or draw.

The Tumbling Duke Sample

In figure 6.1, you saw the animated Duke wave and tumble. The Tumbling Duke sample applet is more of the same as Duke makes his way across your screen doing cartwheels all along the way.

The Jackhammer Duke Sample

When Duke finishes dancing across your screen, he will get his jackhammer and break some concrete in the Jackhammer Duke applet.

The Wireframe Sample

A wireframe is a 3-D outline of an object. The Wireframe sample applet starts by offering you the following four choices:

The four options produce molecular structures like the one in figure 6.14. The applet demonstrates once again how you can animate three-dimensional Web page figures.


FIG. 6.14

The Cube's molecular structure.

Summary

The goal of this chapter was to let you load, execute, and play with some of the sample applets that Microsoft supplies with Visual J++. By running the applets, you not only gain experience with the Developer Studio, but you also get a better idea of Visual J++'s and Java's power.

As you learn new Java commands throughout this book, refer back to this chapter and study the samples to gain insight into Java programming methods. Perhaps you can adapt your own programs from some of the programs you see in the sample collection.

The next chapter uses some of the sample applets and lets you modify their behavior without changing any program code! One of Java's primary advantages is its extensible nature. By extending a sample and changing behavior, you can change the way the sample works.

The following list the points this chapter covered:


Previous Page TOC Next Page

| Previous Chapter | Next Chapter |

| Table of Contents | Book Home Page |

| Que Home Page | Digital Bookshelf | Disclaimer |


To order books from QUE, call us at 800-716-0044 or 317-361-5400.

For comments or technical support for our books and software, select Talk to Us.

© 1996, QUE Corporation, an imprint of Macmillan Publishing USA, a Simon and Schuster Company.