Docsity

Guide to Creating, Compiling, and Running Java Programs using TextPad - Prof. Y. Daniel Li, Study notes of Computer Science

Toggle sidebar
bg1
Supplement II.A: Creating, Compiling, and Running
Java Programs from TextPad
For Introduction to Java Programming
By Y. Daniel Liang
This supplement covers the following topics:
• Introducing TextPad UI
• Creating a Java Program
• Compiling a Java Program
• Running a Java Program
• Creating and Running a Java Applet
1 Introduction
TextPad is a shareware Java IDE. It provides editing,
compiling, and running Java programs from a single user
interface. It is a simple tool for novice users to develop
Java programs. You can also download it from
www.textpad.com. You need to install JDK before installing
TextPad. JDK 1.5 can be downloaded from
http://java.sun.com/j2se/1.5/download.html.
Assume you have successfully installed JDK 1.5 and TextPad.
Start TextPad. The main user interface appears as shown in
Figure 1.
Figure 1
The TextPad main window is the command center for the IDE.
The TextPad main window contains menus, toolbars, file pane,
© Copyright Y. Daniel Liang, 2005
1
pf3
pf4
pf5

Partial preview of the text

Download Guide to Creating, Compiling, and Running Java Programs using TextPad - Prof. Y. Daniel Li and more Study notes Computer Science in PDF only on Docsity!

Supplement II.A: Creating, Compiling, and Running

Java Programs from TextPad

For Introduction to Java Programming By Y. Daniel Liang

This supplement covers the following topics:

  • Introducing TextPad UI
  • Creating a Java Program
  • Compiling a Java Program
  • Running a Java Program
  • Creating and Running a Java Applet

1 Introduction

TextPad is a shareware Java IDE. It provides editing, compiling, and running Java programs from a single user interface. It is a simple tool for novice users to develop Java programs. You can also download it from www.textpad.com. You need to install JDK before installing TextPad. JDK 1.5 can be downloaded from http://java.sun.com/j2se/1.5/download.html.

Assume you have successfully installed JDK 1.5 and TextPad. Start TextPad. The main user interface appears as shown in Figure 1.

Figure 1

The TextPad main window is the command center for the IDE.

The TextPad main window contains menus, toolbars, file pane,

1

editor pane, and reference pane.

1.1 The Main Menu The main menu is similar to that of other Windows applications and provides most of the commands you need to use TextPad, including those for creating, editing, compiling, and running. The menu items are enabled and disabled in response to the current context.

1.2 The Toolbar The toolbar provides buttons for several frequently used commands on the menu bar. The toolbars are enabled and disabled in response to the current context. Clicking a toolbar is faster than using the menu bar. For many commands, you also can use function keys or keyboard shortcuts. For example, you can save a file in three ways:

  • Select File, Save from the menu bar.
  • Click the "save" toolbar button

( ).

  • Use the keyboard shortcut Ctrl+S.

TIP:

You can display a label known as ToolTip for a toolbar button by pointing the mouse to the button without clicking.

1.3 The File Pane The file pane displays all files currently opened in TextPad.

1.4 The Editor Pane The file pane displays the content of the file selected in the file pane.

1.5 The Reference Pane The reference pane gives the user a quick reference on ANSI Characters, Control Characters, DOS Characters, HTML Characters, and HTML tags.

2 Creating a Java Program

Let us use Example 1.1 and Example 1.2 demonstrate creating a Java program from TextPad.

Every time you start TextPad, a blank document named

2

Figure 4

You can save the source code into .java file.

To create a new Java source code file for Example 1.2, choose File , New. Document2 appears in the file pane. Type the code for Example 1.2 in the editor pane as shown in Figure 5. Choose File , Save As to save the file as a .java file named WelcomeInMessageDialogBox, as shown in Figure 5.

Figure 5

A new file is created for WelcomeInMessageDialogBox.java.

3 Compiling a Java Program

To compile Welcome.java, select Welcome.java in the file pane, choose Tools , Compile Java.

4

Figure 6

You can compile Java programs from the TextPad.

4 Running a Java Program

To run Welcome.java, select Welcome.java in the file pane, choose Tools , Run Java Application. A DOS command prompt is started to display the output from the print statement, as shown in Figure 7.

Figure 7

You can run Java programs from the TextPad.

5 Creating and Running a Java Applet

Let us use Example 12.1 demonstrate creating and running Java applets. You can create a MortgageApplet.java in the same way you create a Java program. To create MortgageApplet.html, choose File , New to create a file and save it as .htm file, as shown in Figure 8.

5