Java Programming
CIS279
Tori Basford
tori@bly.net
Assignment(s):
CIS 279 - Homework 1, Part d
Exercise(s):
Converting:
As with the 8 Primary data types, different things (Components, for example) can be converted. All things can be converted to Objects.
example:
Object o = new Object();
Component cp = (component) o;
Object o = (Object) cp;
Hashtable:
Hash tables contain a key (object) and a value (object) that coresponds to the key. things are stored and retrieved from the hash table via the put(key object, value object) and get(key object) methods.
example:
Hashtable ht = new Hashtable();
ht.put("Tori", "teacher");
ht.put("Pima", "8181 E. Irvington");
ht.put("CB", new ColorBar());
Object o = ht.get("Pima");
String s = (String) o;
In order to put the 8 primary data types into a hash table, use the Class for each data type to convert them to an object.
More on ColorBar:
Suppose cb is a ColorBar, and we want to find out where the SCrollBar is set. We could use the cb.jsb.getValue); method, but accessing from the outside is not a good idea. Because of this, we should set the JScrollBar to private and create a method to get the value. This should be set to getValue() and should return the value of the ColorBar's JScrollBar.
We need to be able to add a Listener of our own to the ColorBars in CBTest, but we can NOT use the cb.jsb.addAdjustmentListener(al) method because jsb is now private. So, in ColorBar a method should be made (aal(), for example) that recieves an AdjustmentListener and addes to the JScrollBar (jsb).
cb.a
cb1.aal(al);
In the ColorBar.aal, it runs the command jsb.addAdjustmentListener(al) which passes the AdjustmentListener that was given to aal().