MultiEd's Icon

Tutorial
Editing Java Files

This tutorial will show you how to use some of MultiEd's special features to simplify creating a Java document.

It assumes that the Java SDK has been installed on your computer, that the system has been set up to know where the Java programs are stored. (See Setting up Java , if needed.) It also assumes the tool buttons "Java compile and run" and "Java run" were included when the programmable tools buttons were set up. (See MultiEd's Tool Setup Program, if needed.) They are included in the default setup of MultiEd.

  1. Open a new .java file and save it an appropriate folder. There are two ways to do this:
    a. Click on the new button New file button and ask for an .java file. Then use the File menus "Save As" option to save it to an appropriate place with an appropriate name. (Use "Test.java" in this tutorial.)
    or
    b. Click on the open button Open file button, select an appropriate folder, and type the desired file name (e.g. Test.java). Important: Be sure to include the file type (.java).
  2. Click the template button. Template button (By default it is tool button number 9 but it may have been moved). The open dialog has a list of templates that can be used for Java. Pick a template that corresponds to the type of program you want to create. For this tutorial, we will suppose that we want to create an Applet. Select the desired template. MultiEd will write the basic structure of a Java applet for you.
    Selecting the template (The list of available templates will vary.) Select a template
    The first part of the resulting file. Result using template
  3. (Optional) Click the Java compile and run tool button Web button. (There will be multiple buttons that look like the one shown. Pick the one whose tool tip says "Java compile and run".)

    MultiEd will compile your program. After the file compiles correctly, it will try to run it. It detects "extends Applet" in the file and checks to see if can find a corresponding .html or .htm file (Test.html or Test.htm in our example). If it can't, it creates a very simple default file (TestDefault.html in our example). It then load the applet into the Applet Viewer. In this case the applet is blank because we haven't added anything to the basic structure provided by the template.

  4. Lets create a more interesting program. Write some Java into the file. Lets just keep it really simple by adding to the paint method.
    Edited file
  5. Click the Java compile and run tool button Web button. The applet will be loaded into the Applet Viewer. Web button The result should look like that shown on the right. Actually your window will probably be larger. In our simplistic applet, we do not need the "implements ActionListener, AdjustmentListener" and the actionPerformed and adjustmentValueChanged methods so the could be carefully eliminated.
  6. Repeat steps 4 and 5 as needed to complete the program as desired.
  7. Click the tool button with the tool tip "Java run" Web button to run the completed program without recompiling it.

Hint: You may want to resize your applet or create a web page for it. You can do so by creating a page Test.html. After you create and save the blank file, you can use an a template (template-ForApplet.html) to create a simple web page and customize it. You can run the page in the Applet Viewer by using the "Java run" button while viewing the Java program or in a browser using a web button Find brace button while viewing the .html file.

Hint: Java programs require many match pairs of curly brackets { }. The indent lines provide one way to keep track of them. Another uses the "Find brace" tool. Put the cursor one curly bracket, click the "Find brace" tool button Find brace button and MultiEd will move the cursor to the matching bracket. The button also works with the pairs ( ), < >, and [ ].

Hint: If your Java program is long or consists of several files, you may want to create a project. The MultiEd directory contains a subdirectory called "ExampleProject" that illustrates projects. See the MultiEd's Help item "What is a project?" or the Creating and Using Projects Tutorial to learn how to create a project. It is pretty simple.


Appendices

The following sections explain how to setup Java. They can be skipped if this has already been done.


Installing and Setting Up Java's JDK

In order to automatically use the tool buttons to compile and run Java, the JDK (Java Development Kit) must be installed on the user's computer. The compiler and documentation is available from
http://java.sun.com/.
As of the time this tutorial was written, the current version was referred to as J2SE 5.0 or JDK 5.0 Update x. It could be downloaded from
http://java.sun.com/j2se/1.5.0/download.jsp
but new versions and updates appear frequently. Be sure to download the JDK which includes the compiler. It also includes JRE (Java Runtime Environment) which is intended to allow you to run Java Applets in a browser. (The NetBeans IDE bundle is NOT required but can be used.)

BE SURE TO READ: the "Installation instructions" provided in a separate link on the download page. Those instructions tell you how to set the "PATH" ENVIRONMENTAL VARIABLE which makes it easy to compile and run Java programs. Make sure you follow the instructions for your version of Windows.

When setting the PATH variable, you should check for an CLASSPATH variable as well. If it already exists, add ".;" to the beginning of it. If not, it may be best to create your own setting CLASSPATH to "." (a period). While this is the default, some programs will set their own CLASSPATH when they are installed and it probably will not include the ".;" term unless it is already there. Note: "." represents the current folder, what ever it may be.

The download page also allows you to download Java Documentation. (This was called "J2SE 5.0 Documentation" when this tutorial was written.) You may find convenient to download it even though it is available on line. It will be easiest if it saved in the folder C:\Program Files\Java\ but this location can be changed as needed.

Return to beginning of the Tutorial


MultiEd's Tool Setup Program

The MultiEd download includes several programmable tool buttons that are useful when working with Java. Four of those are designed especially for Java and have a coffee cup icon.

ToolSetup.window You can run the ToolSetup.exe program to select the tool buttons you wish to use. Close MultiEd if it is open before running this program which is in the MultiEd folder. The figure shows 7 tools buttons that are useful when using Java. The buttons can be assigned to different numbers if desired. Tools 6 and 7 can be used for other purposes and do not have to blank as shown.

To change tool buttons:

Close MultiEd if is open. The top left section shows the available tools and the top middle section shows those that have been installed. To remove an installed tool button, click its left arrow. To assign an available tool, select the tool and then click the right arrow of an unused tool. When you are finished click the close button and say "Yes" when you are asked if you want to save the new setup.

Return to beginning of the Tutorial


Revised Feb. 2, 2006