How to refresh Papplet based on user input
in
Contributed Library Questions
•
7 months ago
Hi All,
I have requirement that showin tags from DB as wordcloud and on change of tag type from the ui page, wordcloud needs to generate as per the tag type.
To generate wordcloud, I've used WordCram inside PApplet. My setup(), draw() methods are as below.
WordCram words;
Word[] w;
public void setup() {
size(1000,1000);
//this.add("toolTipPanel", new Imagepanel());
words = new WordCram(this);
//cp = new ControlP5(this);
}
public void draw() {
background(200);
Color c = new Color(139,0,0);
System.out.println(" c.getBlue() : "+c.getBlue());
for ( int i=0; i < w.length; i++) {
if(w[i].weight>=5.0)
w[i].setColor(c.BLUE.getRGB());
if(w[i].weight<5.0)
w[i].setColor(c.RED.getRGB());
if(w[i].weight>10.0)
w[i].setColor(c.GREEN.getRGB());
}
this.words.fromWords(w);
words.maxAttemptsToPlaceWord(1000);
this.words.drawAll();
Word[] s=words.getSkippedWords();
for(int i=0;i<s.length;i++) {
System.out.println(" "+s[i].wasSkippedBecause());
switch (s[i].wasSkippedBecause()) {
case WordCram.SHAPE_WAS_TOO_SMALL:
System.out.println(s[i].word + ": shape was too small");
break;
case WordCram.WAS_OVER_MAX_NUMBER_OF_WORDS:
System.out.println(s[i].word + ": was over max # of words");
break;
case WordCram.NO_SPACE:
System.out.println(s[i].word + ": no room to place it");
break;
}
}
// Method gets called from the UI page on change of the value of Tag type.
public void changeWords(int val) {
if(val ==1 ) {
System.out.println("val = "+val);
w = new Word[50];
w[0] = new Word("Hello",5);
w[1] = new Word("World",2);
w[2] = new Word("Timely",3);
w[3] = new Word("Incomplete",5);
w[4] = new Word("Good",8);
w[5] = new Word("Excellent",10);
w[6] = new Word("Bad review",2);
w[7] = new Word("Average",5);
w[8] = new Word("Very bad",1);
w[9] = new Word("Optimal",7);
w[10] = new Word("Nice work",9);
w[11] = new Word("Very low",3);
w[12] = new Word("Outstanding",11);
w[13] = new Word("Highly rated",9);
w[14] = new Word("Imperfect",4);
for(int i=15;i<50;i++)
w[i]=new Word("Test"+i,3);
}
if( val == 2) {
System.out.println("val = "+val);
w = new Word[15];
w[0] = new Word("Swarupa",5);
w[1] = new Word("Sreedevi",2);
w[2] = new Word("Abi",3);
w[3] = new Word("Vijji",5);
w[4] = new Word("Nagu",8);
w[5] = new Word("Sandhya",10);
w[6] = new Word("Swetha",2);
w[7] = new Word("Chandrakala",5);
w[8] = new Word("Tharani",1);
w[9] = new Word("Noushin",7);
w[10] = new Word("Siva",9);
w[11] = new Word("Priyanka",3);
w[12] = new Word("Anupama",11);
w[13] = new Word("Parvathi",9);
w[14] = new Word("Chetana",4);
}
}
Even though, I am able to see the value from UI input, my applet is not getting reloaded with new words.
Any poinerts on this.
1