how to get data from arraylist
in
Programming Questions
•
2 years ago
Hi, I worked for few days to make this possible: press the mouse to draw a freehand line, when mouseReleased, the freehand line creep forward like a worm. I wrote part of the code as follows, but now I cannot go any more front.
- ArrayList mouseMove;
PFont font=createFont("TrueFrutigerLight",24,true); - void setup() {
size(600,400);
smooth();
mouseMove=new ArrayList();
} - void draw() {
background(255);
for(int i=0;i<mouseMove.size();i++) {
DrawLine myLine=(DrawLine)mouseMove.get(i);
myLine.dLine();
}
if (mousePressed == true) {
mouseMove.add(new DrawLine(mouseX,mouseY,pmouseX,pmouseY));
}
fill(0);
textFont(font);
textAlign(CENTER);
text(mouseMove.size(),width/2,30);
} - /*
void mouseReleased(){
for(int j=mouseMove.size()-1;j>0;j--){
mouseMove.remove(j);
}
}*/ - class DrawLine {
float x1;
float y1;
float x2;
float y2; - DrawLine(float a,float b,float c,float d) {
x1=a;
y1=b;
x2=c;
y2=d;
} - void dLine() {
stroke(150);
strokeWeight(2);
line(x1,y1,x2,y2);
}
}
-
how can I get mouse trace position coordinate values from ArrayList? Or you will have better ideas to achieve that.
1