Sei sulla pagina 1di 4

DynamicBillboard applet

The DynamicBillboard applet displays a sequence of images by repeatedly changing the image on the screen to another after a period of time. This applet was designed by Robert Temple when he was working at at Embry-Riddle Aeronautical University in Florida.The transition between one image and the next is done with one of a variety of special effects. The DynamicBillboard applet provides web sites with an elegant way to rotate ads, banners, or billboards on a single static page. The applet links to other pages through a URL associated with each image. When the user presses the mouse button with the cursor over the applet, the browser will go to the new page associated with the current image. The applet consists of three main classes and any number of transition classes.The three main classes are DynamicBillboard, BillData, and BillTransition. 1. DynamicBillboard.java This is the main applet class. It implements Runnable to include a thread that controls the continuous process of creation and animation of the transitions. The transition classes array stores the names of the transition classes as strings. It uses strings because it loads these classes dynamically using the method java.lang.Class.forName(String). This allows the applet to put off the loading of these classes until they are first instantiated. 2. BillData.java The BillData class is mostly just a data structure for encapsulating attributes associated with individual billboards. It contains three variables. The first variable stores the URL to which the billboard is a link. The second variable has an Image that the applet uses to draw on the screen. The third variable includes a pixel array of the image in RGB format. The pixel array is used by transitions in combination with another BillData pixel array to create the cells for transition animation. The array is only one-dimensional. The pixels in it are arranged in such a way that the first element in this array is the top-left corner of the image. The second element is the pixel just to the right of this corner. Elements that follow are the pixels to the right of this one, and so on, until the rightmost pixel is reached. Then the leftmost pixel on the next line of the image is used. This continues until the last index in the array, which corresponds to the pixel on the bottom-right corner of the image 3. BillTransition.java The BillTransition class is used as a base class for other transition classes. These other classes create transition cells between two individual billboard images. This abstract class contains variables and methods that are common to all transitions. This applet consist of following transition classes: 1. ColumnTransition.java The ColumnTransition class changes one image into another by drawing increasingly large columns of the new image onto the old image. The column sizes increase to the left, and the same pixels are always drawn on the left side of each column. This makes the billboard appear to be sliding in from behind the old billboard through vertical slots in the current billboard. 2. FadeTransition.java The FadeTransition class changes one image into another by randomly including a number of new pixels from the next billboard in each successive cell frame. This makes the next billboard appear to fade in over the old billboard.

3. SmashTransition.java The SmashTransition class changes one image into another by dropping the new image onto the old one. The old image appears to crumble under the weight of the new image. 4. TearTransition.java The TearTransition creates the illusion of the current billboard getting torn off the applet like a piece of paper. It gets ripped upwards and toward the left to reveal the next billboard image underneath. 5. UnrollTransition.java UnrollTransition makes it appear as if a rolled-up poster is placed on the bottom of the applet and then unrolled upward, gradually revealing the next image and covering the old image. To enhance the unroll illusion, the roll gradually decreases in size as it makes its way upward on the billboard.

ImageMenu: An Image Based Web Menu


The ImageMenu applet is a simple program that presents an image-based menu with an arbitrary number of choices in a vertical list. When the user moves the mouse cursor over these choices, the one under the cursor changes appearance, indicating that it can be clicked on. When the user clicks on a choice, the web browser changes to a new document specified for that choice. ImageMenu was created by David LaValle, the creator of several interesting applets. David LaVallee, who is a senior scientist at Starwave Corporation, created ImageMenu. ImageMenu uses the showDocument() function in AppletContext to make the hypertext leap to new pages. The essence of ImageMenu is that it uses different portions of a single source image to draw the menu on the screen. Basing a menu on an image rather than on a text eases the design of menus that use any font or image desired. Various types of selection feedback can also be provided and there is no longer any need to rely on AWTs limited rendering functions. The ImageMenu applet was inspired by an applet called Navigation, created by Sean Welch. The difference between Navigation and ImageMenu is the efficiency in bandwidth and applet tag specification.

The Lavatron Applet: A Sports Arena Display


Lavatron applet is a sports area light bulb display. Lavatron is able to present an interesting image on screen because of small trick that it employs, and its side effect allows the applet to load very quickly. The reason it loads very quickly is that there is not much data transmitted over the net. The source image is the JPEG image that is 64 times smaller than the displayed image. Each pixel is the source is scaled up to 8 ( 8 pixel square. Lavatron paints so fast because it doesn't have to repaint what it has redrawn. The technique of copying the area of the screen that is good and repainting just the portion that is new in many common operations involving scrolling. The awt.Graphics function copyArea() takes a portion of an image defined by a rectangle and moves it by an x,y offset from its starting location. Lavatron starts by initializing data, which includes loading the source image and creating the column of bulb images. The last stage of the initialization is painting the offscreen (double buffer) image full of dimmed (black) lightbulbs to start the display with a clean image. Subsequent painting of the offscreen image begins by using copyArea( ) to move the existing portion of the image to the left by the width of the column of bulbs

about to be added on the right edge. Then the pixel values for the next column are read and used as the color to fill a column of 88 rectangles at the right edge of the applet. The transparent column of bulbs is painted, and then the whole backing image is drawn to the screen. Since this applet doesnt have to do much except scroll the image, it avoids the normal repaint( ) loop by forking a thread that repeatedly calls paint( ), pausing only to call yield( ) to allow other threads to run.

Scrabblet: A Multiplayer Word Game


Scrabblet is a complete multiplayer, networked client/server game. Scrabblet consists of more than 1400 lines of code in 11 classes. Two of these classes are part of server side of the applet. The other nine are downloaded to a web browser and acts as the simulation of the game. Before users can play a multiplayer game, they must choose somebody to play against. When it is first run it prompts the user to enter name of player which is passed to server, who broadcasts the players name to all other potential competitiors. Then the user sees a list of all available players. Select one and click on challenge. Currently there is no way to confirm or deny challenge. Once a challenge is made, both players see the game board appears, and all other competitors simply see both players names disappear from available list. The client code The following classes are installed and run separately on the client side: 1. Scrabblet.java The main applet class is found in Scrabblet.java. A 2. IntroCanvas.java The IntroCanvas subclass of Canvas is very simple. It just overrides paint( ) to draw the name of the applet and a brief copyright notice. It creates some custom colors and fonts. The display strings are held in static variables simply for clarity. 3. Board.java The Board class encapsulates most of the game logic as well as the look and feel of the board. It is the biggest class in the game, weighing in at over 500 lines of code. There are several private variables that store the game state. 4. Bag.java The Bag class is very clean compared with Board. It is a simple abstraction for the bag of letters 5. Letter.java The Letter class is fairly clean in that it doesnt know anything about the game or the board. It merely encapsulates the position and visual rendering of a single letter. It uses several static variables to hold information about fonts and sizes. AVA 6. ServerConnection.java The last class in the client side of this applet is ServerConnection, which encapsulates the communication with the server and our opponent. There are several variables declared at the beginning of the class. The Server Code The following classes are installed and run separately on the web server that the applet classes are to be loaded from. 1. Server.java Server is the main class for the server side of Scrabblet. 2. ClientConnection.java This class is the mirror image of ServerConnection in the applet. One of these is created for each client. Its job is to manage all of the I/O to and from a client. The private instance variables hold all of the states about this client.

Migrating from C++ to Java


C++ features not supported by Java : 1. Java does not support pointers, because pointers are inherently insecure. 2. Java does not include structures and unions. 3. Java does not support operator overloading. 4. Java does not include a preprocessor directive nor does it support the preprocessor directives. 5. Java does not perform automatic type conversions that result in loss of precision. 6. All the code in Java program is encapsulated within one or more classes. Thus, Java does not have global variables or global functions. 7. Java does not allow default arguments. 8. Java does not support inheritance of multiple superclasses by a subclass. 9. Java does not have destructors. 10. Java does not support typedef. 11. It is not possible to declare unsigned integers in Java. 12. Java does not allow the goto. 13. Java does not have the delete operators. 14. The << and >> in Java are not overloaded for I/O operations. 15. In Java, objects are passed by reference only. In C++, objects may be passed by value or by reference. Features unique to Java : 1. Java supports multithreading . 2. There is no feature in C++ that directly corresponds to a Java package. 3. Java has a streamlined approach to memory allocation. Like C++ it supports new keyword but not have delete. 4. The break and continue statements have been enhanced in Java to accept labels as targets. 5. The char type in Java declares 16-bit-wide Unicode characters. 6. Java adds >>> operator, which performs an unsigned right shift. 7. Java contains a built-in string type called String. 8. In addition to single line and multi-line comments Java supports documentation comment.

Potrebbero piacerti anche