学习 swing看
JTable,JTree ,JList这部分看不下去了。有没完备的文档资料 。我现在看的是 官网源码教程 + 网上资料 + jdk demohttp://download.oracle.com/javase/tutorial/uiswing/components/list.html这部分真的看不进去啊。哦呜
JTable,JTree ,JList这部分看不下去了。有没完备的文档资料 。我现在看的是 官网源码教程 + 网上资料 + jdk demohttp://download.oracle.com/javase/tutorial/uiswing/components/list.html这部分真的看不进去啊。哦呜
{
// Class stuff.
/** Number of names. */
static protected float nameCount; /** Names to use for children. */
static protected String[] names; /** Potential fonts used to draw with. */
static protected Font[] fonts; /** Used to generate the names. */
static protected Random nameGen; /** Number of children to create for each node. */
static protected final int DefaultChildrenCount = 7; static {
String[] fontNames; try {
fontNames = Toolkit.getDefaultToolkit().getFontList();
} catch (Exception e) {
fontNames = null;
}
if(fontNames == null || fontNames.length == 0) {
names = new String[] {"Mark Andrews", "Tom Ball", "Alan Chung",
"Rob Davis", "Jeff Dinkins",
"Amy Fowler", "James Gosling",
"David Karlton", "Dave Kloba",
"Dave Moore", "Hans Muller",
"Rick Levenson", "Tim Prinzing",
"Chester Rose", "Ray Ryan",
"Georges Saab", "Scott Violet",
"Kathy Walrath", "Arnaud Weber" };
}
else {
/* Create the Fonts, creating fonts is slow, much better to
do it once. */
int fontSize = 12; names = fontNames;
fonts = new Font[names.length];
for(int counter = 0, maxCounter = names.length;
counter < maxCounter; counter++) {
try {
fonts[counter] = new Font(fontNames[counter], 0, fontSize);
}
catch (Exception e) {
fonts[counter] = null;
}
fontSize = ((fontSize + 2 - 12) % 12) + 12;
}
}
nameCount = (float)names.length;
nameGen = new Random(System.currentTimeMillis());
}
/** Have the children of this node been loaded yet? */
protected boolean hasLoaded; /**
* Constructs a new DynamicTreeNode instance with o as the user
* object.
*/
public DynamicTreeNode(Object o) {
super(o);
} public boolean isLeaf() {
return false;
} /**
* If hasLoaded is false, meaning the children have not yet been
* loaded, loadChildren is messaged and super is messaged for
* the return value.
*/
public int getChildCount() {
if(!hasLoaded) {
loadChildren();
}
return super.getChildCount();
} /**
* Messaged the first time getChildCount is messaged. Creates
* children with random names from names.
*/
protected void loadChildren() {
DynamicTreeNode newNode;
Font font;
int randomIndex;
SampleData data; for(int counter = 0; counter < DynamicTreeNode.DefaultChildrenCount;
counter++) {
randomIndex = (int)(nameGen.nextFloat() * nameCount);
if(fonts != null)
font = fonts[randomIndex];
else
font = null;
if(counter % 2 == 0)
data = new SampleData(font, Color.red, names[randomIndex]);
else
data = new SampleData(font, Color.blue, names[randomIndex]);
newNode = new DynamicTreeNode(data);
/* Don't use add() here, add calls insert(newNode, getChildCount())
so if you want to use add, just be sure to set hasLoaded = true
first. */
insert(newNode, counter);
}
/* This node has now been loaded, it so. */
hasLoaded = true;
}
}swing啊 swing,