For various reasons, Java Fun and Games does not present its applets online. Instead, you must download and compile applet source code, and run the resulting applets on your platform.
Recently, JavaWorld has made arrangements with another company, NCE Technologies, to make its online application development platform, DevSquare, available for conveniently building and running Java applets in an online environment. This guide shows you how to install that platform and establish your own free account, log into the online application development platform, set up your own project space, import Java Fun and Games jar files into this space, and run these applets with AppletViewer.
Note:Although Java Fun and Games was created for J2SE 1.4.0, this guide was created from a J2SE 5.0 perspective.
Install the platform and establish your own account
Before you can work with the DevSquare online application development platform, you must install this software and create an account. Complete the following steps to accomplish these tasks:
- Point your Web browser to http://www.devsquare.com
From DevSquare's main Webpage, click the Launch link beside AD Library. If you are running the Mozilla Firefox Web browser, you will be greeted with the dialog box shown below.
Keep the default settings and click the OK button. You are greeted with a Java Loading… message box followed by the Java Web Start dialog box. The latter dialog box checks your platform for the latest installed version of software known as DevSquare. If the software cannot be found, the dialog box downloads several jar files, beginning with nc_client.jar, and validates these jar files. For example, the dialog box shown below is downloading nc_client.jar. The sum of all jar files that are to be downloaded equals approximately 5 megabytes.
After the jar files have been downloaded, the online application development platform starts running. Its first task is to present the login dialog box below, which prompts you to enter a username, a password, and an account name.
Because you do not yet have an account, click the New Account button. You are greeted with the following New Group dialog box, which makes it possible for several developers to share common code and observe each other's changes.
If you are not interested in forming a group, enter your name in the group field. Click the Create Group button, and you are greeted with the following dialog box.
- You must enter a user ID, a password, and reenter that password as confirmation. If someone else from your group has chosen that ID, you will be prompted to reenter the user ID. Once you have finished entering this information, click the Add User button. After a few moments, the online application development platform's GUI appears.
- Click the X button on the main GUI window's caption bar to close the online application development platform. You should notice a DevSquare shortcut icon on the desktop. Whenever you want to access DevSquare, you must click this icon.
Access and import the Java Fun and Games code
- Launch DevSquare by clicking the shortcut on the desktop and log into your account. You will be led to the Development Center by default.
- To access the Java Fun and Games code, you will have to first create a project. Create a project by selecting the Project menu, then Add Project.
Type in your project name. You can choose any project name. The project name should start with an alphanumeric and cannot have special characters. Click OK.
The next screen details the project configuration—main context, user context, server IP, JDK details, among others. You can edit these details later through the Admin Center. Select the particular JDK for your project and click OK.
The next dialog box lists how you can add libraries and change the project settings. Click OK. Your project will be created successfully and the build.xml and web.xml files will be created in the project tree pane.
Next, you will have to import the Java Fun and Gamescode to your project. Navigate to the AD Library Center. Select Studio, then AD Library.
You will find all the Java Fun and Games code in the AD Library Center. Click the JavaWorld node in the left pane and select the code that you want to import. The right pane provides details on the code.
Click the Import to Project button at the bottom. Select the project you want to import the code to and click Import.
You will get the message that the code has been imported to your project. Navigate back to the Development Center. You may wish to refresh the project tree. (Right-click on the project name and click Refresh). The Java Fun and Games code will be available in the project tree. Click the file and it will open in the editor pane on the left. You can edit the file.
Work with the imported Java Fun and Games code
You can edit the imported code without any restriction. The editor features will be available to you by right-clicking within the editor pane or by pulling down the Edit menu. After you have edited the code, you can compile the code by clicking on the Compile icon or pressing the F4 key. The compilation output will be displayed in the bottom pane. If you have made any compilation errors, click on the particular error and the cursor will be placed in the error line.
After you have compiled the Java file, you will want to execute it. Before you execute, you will have to check what kind of file it is. Is it an applet file, a Swing file, or a servlet? Check the code carefully. If the file either extends the
public class <…gt; extends java.applet.Applet) or includes the
init ( )method, then it is an applet. To execute the applet, you will have to first set up the HTML file. Click the Setup Applet options in the Compile & Run menu.
The Applet Options dialog box will come up. Read the instructions listed in the dialog box carefully. The dialog box has two tabs: Applet Info and Main. Enter the HTML file name with the
Go to the Main tab. The contents of the HTML file will display there. You need to specify the
WIDTH(width), and the
AppletName). The height and width are specified as a number and the
AppletNameis specified as packagename/classname with a
In this example, specify the height as 300 and width as 300. The
.classextension should be carefully specified. In this example, we want to set up the CheckerDrag applet present in the funandgames package. The correct path is funandgames/CheckerDrag.class. Ensure that you specify the
AppletNamewithin the double quotes. The Main tab will look as displayed below. Click Save to create the HTML file.
The CheckerDrag.html file will be created and placed in the project tree. If you have incorrectly specified the class name, orhave not completely specified it, orjust want to change the height and width of the applet, click the HTML file in the project tree to open it, make your changes, and save it.
Now that you have set up the applet, you will be eager to see how your applet is displayed and will want to run the applet. You need to be patient for two more steps. To execute your applet, you will have to start your Tomcat instance on the DevSquare server. Select Tomcat Instance and then Start Instance in the Debug menu and start your Tomcat instance.
A small information window will confirm that your Tomcat instance has started. Click OK.
You are now ready to run your applet and enjoy the output. Go to Run Applet with AppletViewer in the Compile & Run menu. The HTML file you created will be listed there. Click on the file and the applet will execute.
This is how the CheckerDrag applet will be displayed. Enjoy the games and have fun with Java.
If you have trouble compiling and running Java Fun and Games software with DevSquare, please email email@example.com