[2395] in java-interest
Re: peer classes?
daemon@ATHENA.MIT.EDU (Jim Graham)
Sat Sep 30 08:26:23 1995
Date: Thu, 28 Sep 1995 12:04:02 -0700
From: flar@bendenweyr@Sun.COM (Jim Graham)
To: java-interest@java@Sun.COM, lemay@lne.com
> The beta JDK comes with a package called java.awt.peer, which contains
> Interface classes that parallel the classes in java.awt.
The java.awt classes implement the public API that applet developers will
use to manipulate their UI components. But, those classes do not actually
implement the on-screen widgets that appear for the user, they simply
delegate to other classes whose job it is to perform the graphical
manipulations to achieve the desired java.awt API.
The classes that implement these on-screen instances of the various components
are in the java.awt.peer package. Actually, most of the "things" in the
java.awt.peer package are just interfaces and the default Toolkit object
contains factories to produce objects which implement these peer interfaces.
In other words, the java.awt.Button class defines the API for any button
that a Java Toolkit might supply. That class may also contains the
implementation of some of that functionality that is instance-independent
but mostly it just delegates to the peer object. The peer object for
that Button, which must implement the java.awt.peer.ButtonPeer interface
is the class that manipulates the Motif button, or the Windows button,
or the Mac button, or whatever toolkit the implementation will use...
> Poking around in those classes, and in the source for AWT itself,
> I'm seeing references that mention that the peers are used to
> "modify the appearance of an object without changing its functionality."
In other words, by substituting a different Toolkit object as the
default Toolkit and returning different peer objects, you could change
the whole applet from Motif-look to Openlook-look or even Mac-look
without having to modify the java.awt classes, since the java.awt
classes rely on the default Toolkit to produce their peer objects
for them. That way, an applet can actually do a "new java.awt.Button(...)"
and not have to worry about the fact that the classes which implement
the graphical button itself will be different on the Windows implementation
and the Mac implementation...
...jim
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com