Help with creating a class
in
Programming Questions
•
8 months ago
Hello guys, total newbie here. I am creating an application that mines data from twitter and represents each of them as an ellipse. I want the actual tweet to show up on mouseover, but since I have the ellipses randomly positioned as x and y, their values keep changing with each loop, making it impossible for me to get the actual coordinates. I figured I will create a class that draws each tweet as an ellipse, so I can call the class and add behavior to it. I am having so much trouble making the class work. I keep getting errors. Please help!
- boolean rollover = false;
- boolean wrd = false;
- boolean wrd2 = false;
- String msg;
- ArrayList message;
- float x;
- float y;
- float radius;
- GeoLocation loc;
- double lo;
- double la;
- float castLat;
- float castLon;
- boolean retweet;
- public boolean ss;
- User user;
- long follow;
- String city;
- String lang;
- String tz;
- long rtCount;
- String reply;
- String keywords[] = {"restaurant"};
- String keyword1 = "burgers";
- String keyword2 = "sandwich";
- void setup() {
- //frameRate(1);
- PFont font = loadFont ("HelveticaNeue-48.vlw");
- textFont(font, 20);
- background(#0A4A4F);
- size(1280, 720);
- noStroke();
- smooth();
- connectTwitter();
- twitter.addListener(listener);
- if (keywords.length==0) twitter.sample();
- else twitter.filter(new FilterQuery().track(keywords));
- }
- static String OAuthConsumerKey = "";
- static String OAuthConsumerSecret = "";
- static String AccessToken = "";
- static String AccessTokenSecret = "";
- TwitterStream twitter = new TwitterStreamFactory().getInstance();
- // Initial connection
- void connectTwitter() {
- twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
- AccessToken accessToken = loadAccessToken();
- twitter.setOAuthAccessToken(accessToken);
- }
- // Loading up the access token
- private static AccessToken loadAccessToken() {
- return new AccessToken(AccessToken, AccessTokenSecret);
- }
- class Drawdata {
- StatusListener listener = new StatusListener() {
- public void onStatus(Status status) {
- try {
- message = new ArrayList();
- message.add(msg);
- loc = status.getGeoLocation();
- la = (float) loc.getLatitude();
- lo = (float) loc.getLongitude();
- castLat = map((int)la, -90, 90, 0, 500);
- castLon = map((int)la, -180, 180, 0, width);
- retweet = status.isRetweet();
- follow = user.getFollowersCount();
- city = user.getLocation();
- } catch(Exception e) {}
- try {
- x = random(0, width);
- y = random(0, height - 200);
- radius = map(status.getUser().getFollowersCount(), 0, 10000, 5, 30);
- float d = dist(x, y, mouseX, mouseY);
- user = status.getUser();
- lang = user.getLang();
- tz = user.getTimeZone();
- rtCount = status.getRetweetCount();
- reply = status.getInReplyToScreenName();
- ss = status.isFavorited();
- msg = trim(status.getText());
- for (int i = 0; i < message.size(); i++) {
- println(message);
- if (match(msg, keyword1) != null) {
- if (match(tz, "US") != null) {
- fill(#E5E539, 70);
- ellipse(x, y, radius, radius);
- noStroke();
- fill(#1C1C1C);
- rect(0, height - 200, width, 200);
- fill(230);
- textSize(16);
- text(msg, 50, height - 160);
- }//closes second if statement
- }
- if (match(msg, keyword2) != null) {
- if (match(tz, "US") != null) {
- fill(#F26453, 70);
- ellipse(x, y, radius, radius);
- noStroke();
- fill(#1C1C1C);
- rect(0, height - 200, width, 200);
- fill(230);
- textSize(16);
- text(msg, 50, height - 160);
- }
- }
- }
- } catch(Exception e){
- }
- } // closes onStatus
- public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
- //System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
- }
- public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
- // System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
- }
- public void onScrubGeo(long userId, long upToStatusId) {
- System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
- }
- public void onException(Exception ex) {
- ex.printStackTrace();
- }
- };
- }
- void draw() {
- //I will like to call the class here
- }
1