I am having some problems with the above (Chapter 7 of Ben's book). I have previously used this example with success but I am unable to publish any treemaps at the moment.
I have created the basic example as defined at the begin of the treemap section, my code:
class WordItem extends SimpleMapItem { String word;
WordItem(String w) { this.word = w; }
void draw() { fill(255); rect(x,y,w,h);
fill(0); if (w > textWidth(word) + 6) { if (h > textAscent() + 6) { textAlign(CENTER, CENTER); text(word, x + w/2, y + h/2); } } } }
class WordMap extends SimpleMapModel { HashMap words;
if (item == null) { item = new WordItem(word); words.put(word, item); } item.incrementSize(); }
void finishAdd() { items = new WordItem[words.size()]; words.values().toArray(items); } }
import treemap.*;
Treemap map;
void setup() { size(1024,768);
smooth();
strokeWeight(0.25f);
PFont font = createFont("Serif", 13); textFont(font);
WordMap mapData = new WordMap();
String[] lines = loadStrings("equator.txt"); for (int i = 0; i < lines.length; i++) { mapData.addWord(lines[i]); } mapData.finishAdd();
map = new Treemap(mapData, 0, 0, width, height);
noLoop(); }
void draw() { background(0); map.draw(); }
When I run this on my computer, all is fine - it looks like the screen shot in the book.
If I then export this, copy the contents of the applet directory to my webserver directory (on my own machine) and then try and load it with my browser (Opera in this case), I get the following:
java.lang.RuntimeException: java.lang.NoClassDefFoundError: treemap/MapModel at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3013) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1444) at java.lang.Thread.run(Thread.java:637) Caused by: java.lang.NoClassDefFoundError: treemap/MapModel at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389) at java.lang.Class.getConstructor0(Class.java:2699) at java.lang.Class.newInstance0(Class.java:326) at java.lang.Class.newInstance(Class.java:308) at sun.plugin2.applet.Plugin2Manager$12.run(Plugin2Manager.java:2955) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199) at java.awt.EventQueue.dispatchEvent(EventQueue.java:633) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) Caused by: java.lang.ClassNotFoundException: treemap.MapModel at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:183) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 14 more Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: treemap/MapModel
Could anyone help, I am pulling my hair out trying to get to the bottom of this. Like I say, I have previous published treemaps without any problems.
The Treemap.jar is included in the applet directory and the MapModel class file is included in the Treemap.jar file.