Download Java Tutorial PDF

TitleJava Tutorial
File Size876.6 KB
Total Pages90
Table of Contents
                            Developing Java Applications: A Tutorial
	What You’ll Learn in This Tutorial
Building a Simple Application
	Creating a Project
		Launch Project Builder
		Choose the New Command
		Name the Project
	Creating the Interface
		Open the Main Nib File
		Resize the Window
		Rename the Window
		Put Text Fields in the Window
		Set Attributes of the Text Fields
		Add Labels for the Text Fields
	Defining the Controller Class
		Identify the Class and Its Superclass
		Specify the Outlets of the Class
		Specify the Action of the Class
	Connecting Objects
		Create an Instance of the Controller Class
		Connect the Controller to Its Outlets
		Connect the Action of the Controller
		Connect the Responders
		Test the User Interface
	Implementing the Controller Class
		Generate the Source Code Files
		Modify the Source Code Files
		Implement the convert Method
		Write a Patch for Windows Applications
	Building and Running the Application
		Build the Project
		Launch and Test the Project
Creating a Custom View Class
	Defining the Custom View Subclass
		Place and Resize the CustomView Object
		Specify the Subclass
		Assign the Class to the CustomView
	Connecting the View Object
		Specify a Controller Outlet
		Connect the Instances
	Implementing the Custom View
		Generate the .java File
		Implement the Constructor
		Implement the Image-Setting Method
		Call the Image-Setting Method
	Completing the Application
		Add Images to the Project
		Build the Project
		Test Drive the Application
	Creating a Subclass of NSView
		Define a Custom Subclass of NSView
		Implement the Code for a Custom NSView
			Drawing
			Invalidating the View
			Event Handling
			An Example
Debugging Java Applications
	Preparing to Debug an Application
		Install Debug Libraries on Windows NT
		Build for Debugging
		Access the Java Debugger
	Using the Java Debugger
		Set and Manipulate Breakpoints
		Step Into and Over Code
		Get a Backtrace and Examine a Frame
		Examine Objects and Variables
			Printing a value:
			Printing a reference (object):
			Printing a reference (class):
			Printing an object:
			Printing the receiver (this):
		Debug Multiple Threads
	Debugging Java and Objective-C Simultaneously
		Set Up For Debugging
		Run both gdb and the Java Debugger
		Switching Between JavaDebug and gdb
	Java Debugger Command Reference
		Getting Help
		Thread Commands
		Stack and Data Inspection
		Control Functions
		Convenience Functions
Developing Java Applications— Concepts
	Fast Track to Java Development
	The Yellow Box’s Java Feature
	The Java Bridge
	Developing 100% Pure Java Applications
	A Project Window
	Project Indexing
	What’s a Nib File?
		When You Load a Nib File
		Connections and Accessor Methods
	The Windows of Interface Builder
	The View Hierarchy and the First Responder
		First Responder and the Responder Chain
	The Target/Action Paradigm
	Model-View-Controller Paradigm
	The Build Panel
                        
Document Text Contents
Page 1

Developing Java Applications: A
Tutorial
Sections

Building a Simple Application

Creating a Custom View Class

Debugging Java Applications

You can now write Mac OS X and Yellow Box for Windows programs in Javaª as
well as in Objective-C, C++, C, and PostScript. You can build a Yellow Box
application that is written exclusively in Java or that is a mix of Java and another
supported language.

This tutorial walks through the basic steps for developing a Java Yellow Box
application with the features available in the current release. The feature set will be
extended and reÞned in future releases, and the procedure will thus be even easier.

Fast Track to Java Development summarizes the different steps in Java development
for programmers with experience in developing Objective-C Yellow Box
applications.

What YouÕll Learn in This Tutorial

In this tutorial you will build a simple application that converts temperature values
between Celsius and Fahrenheit. The application will display a different image
depending on the temperature range. HereÕs what the Þnished application looks
like:
1

Page 2

C H A P T E R


The tutorial has three parts, which you should complete in the following order:

1. Building a simple application. Explains how to create a project and a graphical
user interface, deÞne a custom controller class, and connect an instance of that
class to other objects in the application. It also shows how you must change the
source code Þles generated by Inteface Builder to be valid Java Þles.

2. Creating a custom view. Shows how to create a custom view object using
Interface Builder and Project Builder. (The procedure varies from that for
controller classes.)

3. Debugging Java applications. Illustrates the use of Project Builder and its
JavaDebug facility to debug Yellow Box Java applications. It also shows how you
can debug projects that contain both Java code and Objective-C code.

Related Concepts
Fast Track to Java Development
The Yellow BoxÕs Java Feature
The Java Bridge
Developing 100% Pure Java Applications
2

Page 45

C H A P T E R

Creating a Custom View Class
public boolean acceptsFirstResponder() {
return true;
}

}

Creating a Subclass of NSView 47

Page 46

C H A P T E R

Creating a Custom View Class
48 Creating a Subclass of NSView

Page 89

C H A P T E R
Because of the ControllerÕs central, mediating role, Model objects need not know
about the state and events of the user interface, and View objects need not know
about the programmatic interfaces of the Model objects. You can make your View
and Model objects available to others from a palette in Interface Builder.

Hybrid models. MVC, strictly observed, is not advisable in all circumstances.
Sometimes itÕs best to combine roles. For instance, in a graphics-intensive
application, such as an arcade game, you might have several View objects that
merge the roles of View and Model. In some applications, especially simple ones,
you can combine the roles of Controller and Model; these objects join the special
data structures and logic of Model objects with the ControllerÕs hooks to the
interface.

The Build Panel

The Project Build panel has buttons that do the following:

■ Initiate the build process.

■ Delete the products of the last build(Òmake cleanÓ).

■ Let you set options for the build.

It also shows the results of the build and takes you to the site of any error in the code
when you click the line in the Project Build panel reporting the error.
91

Page 90

C H A P T E R
Figure 0-6 The Build Panel

Panel controls: Build, Make Clean, Options

Error summary
(click line to go
to code site)

Build detail
92

Similer Documents