Given by Nancy J. McCracken at CPS616 -- Information Track of CPS on Spring Semester 97. Foils prepared 19 July 97
Outside Index
Summary of Material
The first part of this talk gives an overview of the extensions and changes in Java now available in JDK 1.1:
|
The second part of this talk goes into more detail on language changes and on the new AWT event model. (Other talks give details on JDBC, security, and JavaBeans.) |
Outside Index Summary of Material
7/17/97 |
Nancy McCracken |
NPAC |
The first part of this talk gives an overview of the extensions and changes in Java now available in JDK 1.1:
|
The second part of this talk goes into more detail on language changes and on the new AWT event model. (Other talks give details on JDBC, security, and JavaBeans.) |
The JDK 1.1 development system including the compiler is available for all platforms except MacOS by downloading from http://www.javasoft.com. JDK 1.1 includes
|
Some features, such as JDBC, which were actually released over last year, are supported in current browsers such as Netscape 3.0. Most AWT stuff is currently only available in HotJava browser (or in JDK 1.1 appletviewer). |
In old event model, the native windowing system reported events to the eventHandler of class Component, who decided which component should get the event and to call a particular event handler for that event, such as "action" or "mouseDown". |
In the new event model, event handling has been more generalized: each class can declare which events it wants to handle by creating an ActionListener for those events.
|
In former releases of JDK, components were implemented by a peer class in the native window system, called "heavyweight components". These have problems:
|
JDK 1.1 has Lightweight UI Framework: subclasses of Component and Container are now implemented wholly in Java code without native code
|
JDK 1.1 has fixed annoying problem of having to create a totally separate class for such structuring things as creating a class to handle a subcomponent of the applet window. You can now create such classes locally within the applet as an inner class.
|
There is a new class Locale which can be used in Java code so that one Java program, a "global program", can be written which uses different character sets, time, date and currency formatting depending on where it is run.
|
Provides the ability to write the complete state of an object to an output stream and then recreate the object later by reading the serialized representation from an input stream. |
Classes ObjectOutputStream and ObjectInputStream have methods to read and write objects (as well as primitive types). |
Used for transferring objects in cut-and-paste, RMI, and JavaBeans. |
Also useful for saving customized or pre-initialized states of objects such as GUI's. |
The first release of the new Java security package has
|
Some of these interfaces are abstract - implementations are provided in "Java Cryptography Extension" (JCE) released separately to JDK "in accordance with U.S. export control regulations".
|
The new JAR file format is for Java Archives - a file that can contain Java classes and other data, such as images and sounds. The JAR format accomplishes several goals:
|
A signed applet from a trusted entity can be downloaded to run under appletviewer with full rights as a local application. They do not run under a regular browser where applets come under the regular "sandbox" restrictions of the Java security model. |
Provides Java interface to legacy databases |
Open interface specification to SQL databases - JDBC classes provide methods for programmers to issue SQL statements and process the results in Java. |
Crucial part is database drivers to provide interface between JDBC classes and the proprietary database product.
|
Goal is to provide platform-independent component architecture. Developer writes reusable software components and then puts together applications from components using a visual builder's tool. |
A Java Bean is a reusable component. It is different from an ordinary class because its method signatures and class definitions allow introspection (by the application builder's tool). Introspection can find
|
Beans also allow persistence - a bean can be customized and then stored back to disk. |
A Bean implements the Java interface "Serializable" which allows the builder tool to work with design time and run time. |
Beans can be simple components like buttons, textfields, scrollbars, etc., or they can be complex entities like calculators or text editors, which were themselves composed out of other components. |
Typically, the builder's tool has a visual interface, akin to Visual Basic or Delphi, in which you can select Bean components to place on your window and hook up events to particular actions. |
The Bean Development Kit (BDK) comes with a testing tool, the Bean Box. |
It also comes with a Bridge for ActiveX and the Migration Assistant for ActiveX. |
Sun is working with a number of other companies on things which, in addition to JavaBeans, will support enterprise computing.
|
Sun is also still working on expanding media API to include more sound classes, mixed stereo, MIDI files |
They are working on performance tools
|
This is a whole set of GUI components being implemented using the Lightweight UI Framework.
|
Makes the "look and feel" of components "pluggable" to allow developers to customize look and feel of applications. |
Swing Set is part of the newly announce Java Foundation Classes (JFC) which is a large collection of classes designed for building visual applications in Java. Some ideas are based on Netscape's Internet Foundation Classes toolkit. Sunsoft, Netscape, IBM, Symantec and Lighthouse Design are collaborating. |
Design work is going on to supply data transfer capability for Java objects, on top of which transfer-protocols can be built. The two API's are
|
A key issue is data format of objects to be transferred - Java is putting in a set of data "flavors" based on MIME types to represent objects. |
As Java classes grow, Sun sees need for Personal Java, a stripped down version of Java with a core set of classes. A prototype has been developed that was used in a version of WebTV demoed at JavaOne. |
Sun has applied to the ISO to become a "submitter of standards" for Java and JavaVM. This requires Sun to conduct an open process for standard development and to ensure a high level of industry participation. |
A class can be defined as a member of another class, analogous to instance variables and methods. |
The code within the member class can refer to any fields and methods of the enclosing class. |
Every instance of a member class is associated with a particular instance of the enclosing class. |
Syntax: public class A { //declare instance variables and methods of A here //methods may create new B private class B { //declare instance variables and methods of B here //methods can refer to instance vars and methods of A } } |
Member classes introduce complications to the name space since there is now both scope (since a member class has a containing class) and inheritance (since a member class can have a superclass). Scope and inheritance form two distinct hierarchies. |
If a member class refers to a name which is both in its containing class and its superclass, the name in the superclass is used as it is considered to be in the current scope, so inheritance takes precedence. |
The Java compiler may require you to make this clear in the syntax by using this.x for an inherited name and A.this.x for a name in containing class A. |
A local class is defined within a block a Java code, typically a method, but also static and instance initializers. |
The local class is only visible within the block of code in which its defined. |
It can use any final (can't be overriden by subclass) local variables or method parameters within its scope. |
Syntax: just declare the class and use it entirely within one block, such as a method. (Note that use of "final" modifier is liberalized.) |
Unlike member classes, local classes can refer to local variables of block they're defined in. |
Typical use of local classes is to define "event listeners". |
There are also anonymous local classes, introduced without a name. Special syntax not covered here. |
All events are represented by the Event class. The instance variable, id, represents the type of the event, such as a button click. Another instance variable, target, specifies the object which generated the event, such as which button. |
Events are dispatched first to the handleEvent() method of the Component in which they occurred. If possible, this method will pass the event on to an appropriate specific event handler such as action(), mouseDown(), etc. |
If the event handler returns true, it handled the event and it's over. Otherwise, handleEvent passes the event on to the container in which that component resides, and so on. |
Based on concept of "event listener":
|
new class java.awt.EventObject is parent of all events, including those for AWT, java.awt.AWTEvent. |
Every event has a source object, obtained by getSource() and a type value, obtained by getID().
|
Event subclasses also have methods for whatever data is needed to handle the event.
|
In the AWT, the event sources are the Components. |
For every event X which a source generates, its API includes methods to register event listeners: addXListener() and removeXListener(). |
List of some components and events they generate:
|
An event listener is a class that you write to handle events. |
For each event type, the java.awt.event package defines an event listener interface. For example, an event listener to receive an ActionEvent must implement the ActionListener interface. (Actually, MouseEvents have two interfaces MouseListener and MouseMotionListener.) |
Each listener interface defines one or more method names, which must be implemented in the event listener. |
ActionEvent ActionListener actionPerformed() |
AdjustmentEvent AdjustmentListener adjustmentValueChanged() |
ComponentEvent ComponentListener componentHidden() componentResized() |
FocusEvent FocusListener focusGained() focusLost() |
ItemEvent ItemListener itemStateChanged() |
KeyEvent KeyListener keyPressed() keyReleased() keyTyped() |
MouseEvent MouseListener mouseClicked() mouseEntered(), mousePressed() mouseReleased() MouseMotionListener mouseDragged() mouseMoved() |
Two ways: write the event listener class, implementing all method names or |
Subclass an adapter class. For each interface that has more than one method, java.awt.event provides an adapter class. This is a class that implements the interface by implementing all method names with an empty body (ignoring event). If you wish to only handle some event types and not others, you can subclass the adapter class and override only those methods used in your application. |
Then your code (applet or application) will create an instance of your event listener class and register it with the event source by calling the addXListener method of the component generating the event. |
ScrollPane is a container that can hold a component area bigger than it shows on the screen. It provides vertical and horizontal scrollers. |
Quite easy to create and add as you would any other container. |
Main difference is that it doesn't have a "natural" size so you should call setSize(n, m) to set its size to n by m pixels. |
PopupMenus are defined with similar methods as regular Menus - there are methods to add menuItems. |
When you add the PopupMenu itself to a component, it doesn't appear in the component window. |
In the MouseListener, in the processMouseEvent() method, you can respond to the user's mouse click in the component by calling the show() method of the PopupMenu to make it appear. |
The items of the PopupMenu can cause events, and you would create event listeners for those events in the usual way. |
Another new AWT feature is that regular Menus can have keyboard MenuShortcuts. |