Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
wait and notify methods of the Object class. In "Using threads in Java, Part II" I took the synchronized threads and created an in-memory communication channel so that two or more threads could exchange
object references. Then in "Using communication channels in applets, Part 3" I applied these communication channels to co-operating applets that were laid out in an HTML page by a Java-aware browser.
These applets combined to create an active HTML page that implemented a simple temperature conversion applet.In this last column on threads and interapplet communication I'll look at a couple issues associated with this approach, and in particular I'll discuss how a layer can be created on top of the existing DataChannel design to allow multiple DataChannels to feed into a single DataChannel. The source code is also online and available for your use, in either an elaborate form, or as a tar or zip archive.
Next month I'll pick on another oft-misunderstood aspect of the Java system, class loaders.
We implement this easily with a DataChannel.
The skeleton of the OptionButton control is as follows:
1 public class OptionButton extends Applet implements Runnable {
2 public void init() {
3 new DataChannel(getparameter("datachannel");
4 state = false;
5 }
6 public void paint(Graphics g) {
7 ... display my label and my choice ring ...
8 }
9 public void start() { ... create the data channel ... }
10 public void stop() { ... release the data channel ... }
11 public void run() {
12 while (thread == currentthread) {
13 value = getValue();
14 current_state = value == myValue;
15 repaint();
16 }
17 }
18 public boolean mouseUp(...) { sendValue(myID); }
19 }
As you can read in the code, the applet is quite simple. The magic is taken care of by the DataChannel. The basic applet knows only two things -- how to render itself in the checked and unchecked state -- and when it gets clicked it sends its value out to its DataChannel, which is the same channel that it is monitoring. When an option button receives a value from its DataChannel, if the value is equivalent to its own value, it sets its checked state to true and repaints itself.
Can you see how it would be modified to be a non-exclusive choice control? Certainly the boundary condition of an OptionButton with no one else in the group would get halfway there. But recall that the way the button gets unset is that some other choice is set. Obviously the mouseUp method would have to implement a toggle rather than a single set semantic. I'll leave it as an exercise for you to create this class (although there is a version in the sources), and when your write it, change the box shape from round to square. This will give users the idea that this is not a single-choice option.