Drop Down Menu Applet





{If you can read this, your browser dosen`t support Java.}
(Drop Down Menu Applet)





A peer based Drop Down Menu Applet. This Applet was designed to mimic "Link.class" (I don't know how close the source code is but but the action is about the same.) while "correcting" the bar location and size anomolys that seemed to arrise with "Link.class". Mainly, the result was my learning something about peer based components.

The source (.java) and binary (.class) files are free for the taking. Have fun. If you think of any unusual ways to use them drop me a line.

DD_Menu.class DD_Menu.java


HTML Code

<APPLET code="DD_Menu.class" width=176 height=21>
<param name=numURLs value="7">
<param name=WinTarget value="_parent">
<param name=aURLin0 value="NJ & Pa Skiing Links|Not a Link">
<param name=aURLin1 value="Jack Frost - Big Boulder|http://209.182.34.181/skiing/passes.html">
<param name=aURLin2 value="Vernon Valley - Great Gorge|http://www.aminews.com/weather/ski_areas/Vernon_Valley_Great_Gorge_NJ_US.shtml">
<param name=aURLin3 value="Shawnee|http://www.shawneemt.com/">
<param name=aURLin4 value="Camelback|http://ski-guide.com/cgi-bin/ski.exe/skitext/pa07">
<param name=aURLin5 value="Belle Mountain|http://skiresortguide.com/cgi-bin/skiarea.exe/overview/nj02">
<param name=aURLin6 value="Hunter Mountain|http://www.huntermtn.com/">
<param name=BG_Color value="blue">
A non Java enabled browser message.
</APPLET>




Peers


When you design a class in Java, you are actually specifying a (or many) component(s). The first part of the specification defines how the component is meant to be used or how it is meant to react. The problem comes from the second part of the specification; how to implementation it. There are two implementation methods available to programmers. The first is to subclass the Canvas & Panel components. (Subclassing the Canvas & Panel components is also called using Peer derived components.) The second method is to derive them directly from Component and Container by rewriting the "Paint" function. There are advantages and disadvantages to each.

Peers are essentially the connection between the abstract object in the Java program and the object which is displayed on the screen. As may be inferred from the previous statement and paragraph, peers are actually created by the native windowing platform and relate the program objects to "already existing objects". They are therefore platform and program dependent.

The abstract object in the program is instantiated with the standard mechanism:
Widget abc = new Widget();
The Peer is created by adding it to the screen image with:
this.add(abc);

The major advantages of using the peer mechanism are:
  • The user does not have to redefine the object (one of the basic tenets of Object Oriented Programming;
  • The GUI object that results is exactly the same as the one the user is used to on that platform; and
  • Data transfer to and from the system clipboard is greatly simplified since the objects that are created and managed by the platform, not by the Java virtual machine.

  • The disadvantages are:
  • System resources (overhead) are required from the platform to manage the peers;
  • The component size, shape and appearance will vary from platform to platform (and program to program on a specific platform).

  • It is the second item which causes the problem with this Applet. The Choice list (Sun call this a "Pop-Up menu" rather than the more descriptive term "Drop-Down menu.") is an example of a peer-based component. On a Motif desktop, Choice creates a raised component with a small 3D hyphen that pops up a 3D menu centered on the item selected. On Windows 95, it creates a recessed component (like a text field) with a button showing a down arrow that pops up a flat menu below the button. Additionally, I tested the component on Netscape 3, Netscape 4, and IE 4 and found that depending on the client used, the component is a different size and is located in a different location within the Applet box. (Actually Netscape 3 and IE 4 are pretty close.) Therefore unless the Applet bounding box has the same background as the remainder of the page, it can easily be seen by users with different clients.

    As stated above deriving objects directly from Component and Container by rewriting the "Paint" function is an alternative to the peer mechanism. For instance, the button applets offered elsewhere on this page are derived in this manner from Component rather than Canvas. The basic advantage of writing a peerless component is the control gained by the programmer. Look is the most important aspect of web design and Peerless components give the this control (Size, Color, Font, Shape etc.) to the programmer.

    One drawback to Peerless components is some of the components change size when activated in a certain manner. Choice in particular acts this way. When the menu is activated, it will (may and in most cases does) cover an area larger than the original Applet bounding box. It is somewhat difficult to imagine how to accomplish this with out the use of peers.