The installation of the applet into a HTML page is very easy. The three PictureButtons get the names "RedButton," "YellowButton" and "GreenButton." These names are written as attribute in the applet tag. Additionally each PictureButton gets the parameter "LinkApplet" with the value "Blackboard." If the user clicks now on a button, then this initiates a search of the HTML page for an applet with the name "Blackboard" and if it finds it then transmit a message to it. As identifier the message is passed the name of the PictureButton as argument.
<applet code=PictureButton.class name=RedButton width=48 height=48>
<param name=LinkApplet value="Blackboard">
...
</applet>
<applet code=PictureButton.class name=YellowButton width=48 height=48>
<param name=LinkApplet value="Blackboard">
...
</applet>
<applet code=PictureButton.class name=GreenButton width=48 height=48>
<param name=LinkApplet value="Blackboard">
...
</applet>
The applet, which is to receive the message from the buttons, gets the name "Blackboard":
<applet code=Blackboard.class name=Blackboard width=279 height=169>
...
</applet>
It receives the messages in the method action and gets the name of the calling PictureButton as argument. Finally, using a simple string comparison it is easy to determine which PictureButton sent the message:
public boolean action (Event event, Object what)
{
// a message from the red button
if (((String) what).equalsIgnoreCase ("RedButton"))
{
...
}
// a message from the yellow button
if (((String) what).equalsIgnoreCase ("YellowButton"))
{
...
}
// a message from the green button
if (((String) what).equalsIgnoreCase ("GreenButton"))
{
...
}
return super.action (event, what);
}
|