0

我正在尝试创建的 Twitter 应用程序存在很大问题。我已经连续两周解决这个问题,每天 14 小时,我无法弄清楚如何解决。我是新手,所以我相信这只是一件简单的事情。

我需要我的推特流一次显示五条推文。然后我需要它删除最旧的推文并用新的推文替换它。现在有人告诉我最好的方法是使用 Linkedlist,这很有意义。但是,每当我尝试合并它时,它都行不通。

如果有人可以帮助我,我将不胜感激,因为此时我已经束手无策了。

这是代码:

import com.francisli.processing.http.*;

import java.util.LinkedList;

//LinkedList myList;


HashMap overall = new HashMap();


HttpClient client;

LinkedList myList;



PImage prhomoPix;

int results_to_show = 5;
int updateTime = 10000;
int updateDiff = 0;



void setup()
{

 myList = new LinkedList();
 for (int i = 0; i < 5; i++) 
 {
   myList.add(client);
 }

  size(1143, 800);



  prhomoPix = loadImage("PrhomoAppBg.jpg");

  background(0);
  image(prhomoPix, 0, 0);


  fill(0, 0, 0, 80);
  noStroke();
  rect(20, 135, 370, 670);

  fill(0, 0, 0, 80);
  noStroke();
  rect(755, 135, 370, 670);

  textAlign(CENTER, CENTER);

}






void responseReceived(HttpRequest request, HttpResponse response)
{


 if(response.statusCode == 200)
 {

    JSONObject allresults;
    allresults = response.getContentAsJSONObject();
    //JSONObject timeline_tweets = response.getContentAsJSONObject();






  for (int i = 0; i < 5; i++)
 {

    text(allresults.get("results").get(i).get("text").stringValue(), 25, 50+(i*120), 330, 330);

  }
  frameRate(2);




//}



   //for (int i=0; i < results_to_show; i++)
  //{

  // text(allresults.get("results").get(i).get("text").stringValue(), 25, 50+(i*120), 330, 330);
 // }

}

      else
  {
    text("UH-OH" + response.getContentAsString(), 50, 50);
  } 
}


void tweetUpdate()
{

  if(millis() > (updateTime + updateDiff))
  {


    client = new HttpClient(this, "search.twitter.com");//what webservice we are using, this is the priate OAuth one. "this" means it is not cpying setting from anywhere else
    client.GET("search.json?q=dublin&rpp="+results_to_show+"&result_type=recent");





    //println(myList);

    updateDiff = millis();

  }  

 }




   void draw()
{
 myList.remove(client);
 myList.add(client);
 tweetUpdate(); 

}

再次非常感谢!

4

2 回答 2

0

To be honest with you, Java is really not my field, but these tutorials looked quite self explanatory. Hope they help.

http://examples.javacodegeeks.com/core-java/util/linkedlist/

于 2013-04-01T23:49:11.753 回答
0
  1. 您必须在方法中重新绘制整个屏幕draw()
  2. 我猜,人们告诉你将推文LinkedList保存在HttpClient.
  3. 更新方法中的推文列表responseReceived()

最终,您的平局将如下所示:

void draw() {
  // repaint
  background(0);
  // draw picture
  image(prhomoPix, 0, 0);
  // repaint all tweets
  for(int i=0; i< tweetsList.size(); ++i {
    drawTweet(tweetsList);
  }
  tweetUpdate(); // update list of tweets from server
}

tweetUpdate()

void tweetUpdate() {
    client = new HttpClient(this, "search.twitter.com");
    client.GET("search.json?q=dublin&rpp="+results_to_show+"&result_type=recent");
}
于 2013-04-02T18:31:56.943 回答