Problem displaying text for the user from a hashmap within a loop
in
Contributed Library Questions
•
2 years ago
Hi,
I am a fairly new programmer using processing and I was wondering if anybody knew how to print the contents of a hashmap, in this case tweets, to the screen within a loop? It seems to be no problem to print to the console but it seems a bit trickier to print to the screen. Here is an extract from the code so far with the problem area in bold:
Line 137: Twitter twitter = new TwitterFactory().getInstance();
HashMap<Long,Tweet> tweets=new HashMap<Long,Tweet>();
...
Line 233: public void searchTwitter(String searchQuery) {
twitter4j.Query query = new twitter4j.Query(searchQuery);
query.rpp(100);
Date referenceDate=new Date();
for(int i=0; i<NUM_SEARCHES; i++) {
String d=new SimpleDateFormat("yyyy-MM-dd").format(referenceDate);
query.until(d);
try {
QueryResult result = twitter.search(query);
for (Tweet tweet : result.getTweets()) {
if (tweets.get(tweet.getId())==null) {
GeoLocation loc=tweet.getGeoLocation();
if (loc!=null) {
tweets.put(tweet.getId(),tweet);
}
} else {
//println("skipping: "+tweet.getId());
}
}
}
catch(TwitterException e) {
println(e.getMessage());
}
referenceDate.setTime(referenceDate.getTime()-TIME_STEP*DAY_DURATION);
}
}
...
Line 268: public void draw() {
for(Tweet tweet : tweets.values()) {
GeoLocation loc=tweet.getGeoLocation();
Vec3D p=new
Vec3D(600,radians((float)loc.getLongitude())-HALF_PI,radians((float)loc.getLatitude())).toCartesian();
// create a box at the computed position
AABB box=new AABB(p,2);
noStroke();
fill(255,120,0);
// draw box at position
gfx.box(box);
print(tweet); - so this prints the tweets to the console in the loop but replacing print with text and an x and y
position throws an error...
fill(255);
Any insights would be great
I am a fairly new programmer using processing and I was wondering if anybody knew how to print the contents of a hashmap, in this case tweets, to the screen within a loop? It seems to be no problem to print to the console but it seems a bit trickier to print to the screen. Here is an extract from the code so far with the problem area in bold:
Line 137: Twitter twitter = new TwitterFactory().getInstance();
HashMap<Long,Tweet> tweets=new HashMap<Long,Tweet>();
...
Line 233: public void searchTwitter(String searchQuery) {
twitter4j.Query query = new twitter4j.Query(searchQuery);
query.rpp(100);
Date referenceDate=new Date();
for(int i=0; i<NUM_SEARCHES; i++) {
String d=new SimpleDateFormat("yyyy-MM-dd").format(referenceDate);
query.until(d);
try {
QueryResult result = twitter.search(query);
for (Tweet tweet : result.getTweets()) {
if (tweets.get(tweet.getId())==null) {
GeoLocation loc=tweet.getGeoLocation();
if (loc!=null) {
tweets.put(tweet.getId(),tweet);
}
} else {
//println("skipping: "+tweet.getId());
}
}
}
catch(TwitterException e) {
println(e.getMessage());
}
referenceDate.setTime(referenceDate.getTime()-TIME_STEP*DAY_DURATION);
}
}
...
Line 268: public void draw() {
for(Tweet tweet : tweets.values()) {
GeoLocation loc=tweet.getGeoLocation();
Vec3D p=new
Vec3D(600,radians((float)loc.getLongitude())-HALF_PI,radians((float)loc.getLatitude())).toCartesian();
// create a box at the computed position
AABB box=new AABB(p,2);
noStroke();
fill(255,120,0);
// draw box at position
gfx.box(box);
print(tweet); - so this prints the tweets to the console in the loop but replacing print with text and an x and y
position throws an error...
fill(255);
Any insights would be great
1