Javascript 如何运行处理+;broswer中的Twitter4j草图
我是一个练习处理的新手程序员,最近我开发了一个使用Twitter4j的草图。当我在处理开发环境中以Java模式运行草图时,它工作得非常好。此外,当我从Java模式导出草图时,生成的应用程序运行良好。但是,当我切换到JavaScript模式并尝试运行草图时,浏览器预览不会显示任何内容 我相信这个问题与Twitter4j有关,因为当我从草图中删除Twitter4j相关代码并运行它(在JavaScript模式下)时,浏览器预览会显示处理视觉效果 我一直在寻找一个解决这个问题的方法,已经持续了好几个小时,跨越了好几天,但是我找不到一个合适的答案。我遇到过一些关于相关问题的帖子,但答案只涉及“签署JAR文件”之类的术语(我认为,这只是与Java模式有关),或者只说明了在浏览器上以JavaScript模式运行草图时出现的问题——不包括涉及使用Twitter4j的草图 我已经在下面附上了我的全部代码的副本,如果能为新手提供一个逐步的答案,我将不胜感激。我正在搜索一个解释,如果可能的话,如何让我的JavaScript模式导出处理+Twitter4j草图在HTML/my网站上运行 谢谢你的时间和技能。我在这篇文章的末尾包括了一些关于代码的注释Javascript 如何运行处理+;broswer中的Twitter4j草图,javascript,html,processing,twitter4j,processing.js,Javascript,Html,Processing,Twitter4j,Processing.js,我是一个练习处理的新手程序员,最近我开发了一个使用Twitter4j的草图。当我在处理开发环境中以Java模式运行草图时,它工作得非常好。此外,当我从Java模式导出草图时,生成的应用程序运行良好。但是,当我切换到JavaScript模式并尝试运行草图时,浏览器预览不会显示任何内容 我相信这个问题与Twitter4j有关,因为当我从草图中删除Twitter4j相关代码并运行它(在JavaScript模式下)时,浏览器预览会显示处理视觉效果 我一直在寻找一个解决这个问题的方法,已经持续了好几个小时
import twitter4j.conf.*;
import twitter4j.*;
import twitter4j.auth.*;
import twitter4j.api.*;
import java.util.*;
Twitter twitter;
String searchString = "#brokendreams";
List<Status> tweets;
int currentTweet;
PFont f;
int amount1 = 300;
Star[] meteors = new Star[45];
StarDust[] sprinkle = {};
String chatter;
void setup() {
size(800,600);
f = createFont("Tahoma", 13, true);
textFont(f, 13);
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("---");
cb.setOAuthConsumerSecret("---");
cb.setOAuthAccessToken("---");
cb.setOAuthAccessTokenSecret("---");
TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();
getNewTweets();
currentTweet = 0;
dustField();
Status status = tweets.get(currentTweet);
for (int j = 0; j < meteors.length; j++) {
meteors[j] = new Star(chatterText());
}
}
void draw() {
background(0, 35, 0);
for (int i = 0; i < sprinkle.length; i++) {
StarDust dust = sprinkle[i];
dust.move();
}
for (int j = 0; j < meteors.length; j++) {
meteors[j].appear();
meteors[j].randomOrbit();
}
chatterText();
}
void dustField() {
for (int i = 0; i < amount1; i++) {
StarDust dust = new StarDust();
dust.swish();
sprinkle = (StarDust[])append(sprinkle, dust);
}
}
String chatterText() {
currentTweet += 1;
if (currentTweet >= tweets.size()) {
currentTweet = 0;
}
Status status = tweets.get(currentTweet);
chatter = status.getText();
return chatter;
}
void getNewTweets() {
try {
Query query = new Query(searchString);
QueryResult result = twitter.search(query);
tweets = result.getTweets();
} catch (TwitterException te) {
System.out.println("Failed to search tweets: " + te.getMessage());
System.exit(-1);
}
}
void refreshTweets() {
while (true) {
getNewTweets();
println("Updated Tweets");
delay(30000);
}
}
class Star {
float x, y;
float xmove, ymove;
float radius;
color linecol, fillcol;
float alpha;
String msg;
float frag1, frag2, frag3, frag4;
Status status;
Star(String message) {
msg = message;
x = random(width);
y = random(height);
radius = random(20, 60) + 10;
linecol = color(random(255), random(255), random(255));
fillcol = color(random(255), random(255), random(255));
alpha = random(200);
xmove = sin(random(2) / 2);
ymove = sin(random(2) / 2);
frag1 = random(radius/5);
frag2 = random(radius/3);
frag3 = random(radius/4);
frag4 = random(radius/2);
}
void appear() {
if (mouseX > x-(radius/2) && mouseX < x+(radius/2) && mouseY > y-(radius/2) && mouseY < y+(radius/2)) {
strokeWeight(1);
stroke(linecol);
noFill();
ellipse(x, y, radius, radius);
} else {
noStroke();
fill(fillcol, alpha);
ellipse(x, y, radius, radius);
}
fill(fillcol);
noStroke();
beginShape();
vertex(x - (radius/3), y + frag1 - frag2);
vertex(x, y - (radius/3));
vertex(x, y);
endShape(CLOSE);
fill(linecol, alpha);
beginShape();
vertex(x, y);
vertex(x, y - (radius/3));
vertex(x + (radius/4), y - frag3 - frag4);
vertex(x + (radius/3), y + frag1 - frag2);
endShape(CLOSE);
fill(fillcol);
beginShape();
vertex(x, y);
vertex(x + (radius/3), y + frag1 - frag2);
vertex(x + (radius/4), y + frag3);
endShape(CLOSE);
fill(linecol, alpha);
beginShape();
vertex(x, y);
vertex(x + (radius/4), y + frag3);
vertex(x + (radius/5), y + frag2);
vertex(x, y + (radius/3));
vertex(x - (radius/3), y + frag1 - frag2);
endShape(CLOSE);
}
void randomOrbit() {
x += xmove;
y += ymove;
if (x > (width + radius)) { x = 0 - radius; }
if (x < (0 - radius)) { x = width + radius; }
if (y > (height + radius)) { y = 0 - radius; }
if (y < (0 - radius)) { y = height + radius; }
appear();
displayTweet();
}
void displayTweet() {
if (mouseX > x-(radius/2) && mouseX < x+(radius/2) && mouseY > y-(radius/2) && mouseY < y+(radius/2) && mousePressed) {
x = mouseX;
y = mouseY;
fill(255);
text(msg, mouseX + 30, mouseY, 200, 200);
mouseReleased();
}
}
void mouseReleased() {alpha = 80;}
}
class StarDust {
float x, y;
float xmove, ymove;
float radius;
float alpha, beta;
Status status;
StarDust() {
x = random(width);
y = random(height);
radius = random(2, 4);
alpha = random(255);
beta = random(155);
xmove = random(1.9) - 0.9;
ymove = random(1.9) - 0.9;
}
void flipColor() {
fill(random(255), random(255), random(255), beta);
stroke(random(255), random(255), random(255), beta);
}
void swish() {
flipColor();
rect(x, y, radius, radius);
}
void move() {
swish();
x += xmove;
y += ymove;
if (x > (width + radius)) { x = 0 - radius; }
if (x < (0 - radius)) { x = width + radius; }
if (y > (height + radius)) { y = 0 - radius; }
if (y < (0 - radius)) { y = height + radius; }
squarespray(xmove);
}
void squarespray(float spray) {
stroke(random(175, 255), random(255), 0, alpha);
strokeWeight(random(7));
point(x + random(radius), y + random(spray));
point(y + sin(spray) * radius, x - spray);
point(random(spray) - 60 + y, random(radius) + x - 30);
}
}
import twitter4j.conf.*;
导入twitter4j.*;
导入twitter4j.auth.*;
导入twitter4j.api.*;
导入java.util.*;
推特;
String searchString=“#brokendreams”;
列出推文;
int-currentweet;
pfontf;
int amount1=300;
恒星[]流星=新星[45];
星尘[]洒水={};
弦颤振;
无效设置(){
规模(800600);
f=createFont(“Tahoma”,13,真);
textFont(f,13);
ConfigurationBuilder cb=新的ConfigurationBuilder();
cb.setOAuthConsumerKey(“--”);
cb.SetOAuthConsumerCret(“--”);
cb.setOAuthAccessToken(“--”);
cb.setOAuthAccessTokenSecret(“--”);
TwitterFactory tf=新的TwitterFactory(cb.build());
twitter=tf.getInstance();
getNewTweets();
currentTweet=0;
达斯菲尔德();
状态=tweets.get(currentTweet);
对于(int j=0;j=tweets.size()){
currentTweet=0;
}
状态=tweets.get(currentTweet);
chatter=status.getText();
回响;
}
void getnewweets(){
试一试{
查询=新查询(搜索字符串);
QueryResult result=twitter.search(查询);
tweets=result.getTweets();
}捕获(twitter异常){
System.out.println(“未能搜索tweets:+te.getMessage());
系统退出(-1);
}
}
无效刷新tweets(){
while(true){
getNewTweets();
println(“更新的推文”);
延迟(30000);
}
}
班级明星{
浮动x,y;
浮动xmove,ymove;
浮动半径;
颜色线颜色,填充颜色;
浮动α;
串味精;
浮子frag1、frag2、frag3、frag4;
地位;
星型(字符串消息){
msg=消息;
x=随机(宽度);
y=随机(高度);
半径=随机(20,60)+10;
linecol=颜色(随机(255)、随机(255)、随机(255));
fillcol=颜色(随机(255)、随机(255)、随机(255));
α=随机(200);
xmove=sin(随机(2)/2);
ymove=sin(随机(2)/2);
frag1=随机(半径/5);
frag2=随机(半径/3);
frag3=随机(半径/4);
frag4=随机(半径/2);
}
空出现(){
如果(鼠标x>x-(半径/2)和鼠标xy-(半径/2)和鼠标y(宽度+半径)){x=0-半径;}
如果(x<(0-半径)){x=宽度+半径;}
如果(y>(高度+半径)){y=0-半径;}
如果(y<(0-半径)){y=高度+半径;}
出现();
displayTweet();
}
void displayteet(){
如果(鼠标x>x-(半径/2)和鼠标x