Chat Tutorial in NetBeans

From Arianne
Jump to: navigation, search

Introduction

NetBeans is a free, open-source Integrated Development Environment (IDE) for software developers that runs on Windows, Linux, Mac OS X and Solaris. Using an IDE for development, instead of the manual editing technique, provides an instant highlighting of syntax and other errors and the ability to run and debug the application within the IDE.

Many developers on Stendhal / Marauroa use Eclipse, but use NetBeans if you prefer; be aware that if you need help it may be limited.

These instructions assume that you will install the minimum required to use the Marauroa engine. Additional features and functions are covered in separate pages.

These instructions have been checked using Windows XP, Java SE Development Kit 7 update 2 and NetBeans 7.0.1 with Marauroa 3.9 (April 2012). Please discuss in the Discussion pages.

The Chat Tutorial

Design

This tutorial will create a simple Chat utility based on the Marauroa engine. Users will be able to register, then login to the Chat Client. Text entered into the client is passed to the Chat Server and echoed to all users that are currently logged in. The development is done in stages, where each stage can be verified. The full functionality will not be complete until the completion of the last stage.

Comments and Javadoc

If you do document your design, there is a chance that it will become detached from the code, or may not be updated when the code is changed. This can be avoided by carefully adding comments to the code. These would reflect the design, so that could be discarded, and comments would be changed when code is changed.

There are three types of comment in Java. You should consider using the appropriate type at relevant places in your code so that others (and even you, after a while away from the code) can understand what your code is doing. Make sure that you comment on why the code is there, not what it is doing if that just repeats the code.

  • A single line comment, which can start on a line of code and runs to the end of the line, is started using // (double slash plus space). The double slash and the rest of that line is ignored.
  • A block of comment, first line starts /* (slash, star plus space) and last line ends */ (space, star plus slash). The block including the first and last lines are ignored.
  • A block of Javadoc (code documentation), first line starts /** (slash, double star plus space) and last line ends */ (space, star plus slash). The block including the first and last lines are ignored. All the code for a project can be examined, using a process in NetBeans, and a page per class file is produced that contains the Javadoc and explains the code without the reader having to read through the code. These are available for the Marauroa classes.

Requirements

Java

The Marauroa engine is written using Java. You will need to install the Java Development Kit (JDK) from Oracle/Java.

NetBeans

NetBeans is downloaded from netbeans.org. It can be extended by installing a large number of plugins; if you are not sure, just use the default installation.

Directory structures

It is usual to develop your code / game in one location (environment) and copy (deploy) the code to another location. The code would be tested, then copied (installed) to a third location where it can be used by the intended audience. This example might be considered trivial enough to skip some of this. More complexity will be covered later.

The following directory structure is one suggestion and is used in the instructions. Choose a different one if you wish.

You will need a location where you can save the files needed for development. The top level location is referred to as DEVPATH. Replace this with whatever you have chosen as that location. Do not create any sub-directories yet. You will copy files from the DEVPATH locations into deployment locations later.

You will need a location for the destination of your developed code. This is referred to as PLAYPATH. Replace this with whatever you have chosen as that location. Do not create any sub-directories yet.

The Chat Tutorial steps

The following steps are required to complete the Chat Tutorial. Read the pages for each target before trying the code.

Optional preliminary target:

First Chat target:

Second Chat target:

If this is now working as expected, it can be extended (see other tutorial projects).