HashMap的问题
processing吧
全部回复
仅看楼主
level 11
XD_Ares 楼主
the type HashMap is not generic;
为什么说HashMap不是泛类型?我用法不对么?是按照api里面来的啊
2016年07月29日 13点07分 1
level 11
XD_Ares 楼主
import java.util.Map;
//HashMap<String,Word> words;
String[] tokens;
int counter;
void setup(){
size(640,360);
HashMap<String,Word> words = new HashMap<String,Word>();
String[] lines = loadStrings("dracula.txt");
String allText = join(lines," ");
tokens = splitTokens(allText," ,.?!:;[]-");
textFont(createFont("Georgia",24));
}
void draw(){
background(51);
fill(255);
String s = tokens[counter];
counter = (counter + 1) % tokens.length;
if(words.containsKey(s)){
Word w = words.get(s);
w.count();
}else{
Word w = new Word(s);
words.put(s,w);
}
float x=0;
float y=height-10;
for (Word w : words.values()){
if(w.count > 3){
int fsize = constrain(w.count,0,100);
textSize(fsize);
text(w.word,x,y);
x+= textWidth(w.word + " ");
}
if (x>width){
x=0;
y-=100;
if(y<0){
break;}
}
}
}
class Word{
int count;
String word;
Word(String s){
word = s;
count=1;
}
void count(){
count++;
}}
2016年07月29日 13点07分 2
level 11
XD_Ares 楼主
求大神指点一下,谢谢啦
2016年07月29日 13点07分 3
1