Java Reference
In-Depth Information
Listing 17-1. Named Vector
import java.util.Vector;
public class NamedVector<E> extends Vector<E> {
String name;
NamedVector(String name) {
this.name = name;
}
NamedVector(String name, E elements[]) {
this.name = name;
for (int i=0, n=elements.length; i<n; i++) {
add(elements[i]);
}
}
public String toString() {
return "[" + name + "]";
}
}
Figure 17-2 shows an example of the NamedVector class in action.
Figure 17-2. Sample JTree with the Vector subclass node
Listing 17-2 shows the source used to generate the example in Figure 17-2.
Listing 17-2. Named Vector Usage
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.util.*;
public class TreeArraySample {
public static void main(final String args[]) {
Runnable runner = new Runnable() {
 
Search WWH ::




Custom Search