guys this is my code. The docs for the library used can be found at processing library docs and unfolding maps library docs. It displays a Google Map in a canvas. The setup() method is called once and then the draw() method is called repeatedly. As soon as I press w button on keyboard the background becomes white as keyPressed() is called.
import processing.core.*;
import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.providers.Google;
public class MyDefaultEventExample extends PApplet {
private UnfoldingMap map;
public void setup(){
size (800, 600, OPENGL);
map = new UnfoldingMap (this, 50, 50, 700, 500, new Google.GoogleMapProvider());
}
public void draw(){
map.draw();
}
public void keyPressed(){
if(key == 'w'){
background (255, 255, 255);
}
}
}
Now I dont precisely understand what actually is happening behind the scenes. I have thought about it and understood something out of it. I dont know if I am correct or not. Please check if this is what actually happens.
According to me -
There is a main method in the PApplet class which gets called as soon as I run the program which is responsible for displaying the canvas and calling the setup() and draw() methods. The pseudocode(not very "precise", just to give a gist of what I feel) which can be used to describe this is
public static void main (){ PApplet myApplet = new PApplet(); myApplet.displayCanvas(); //displays a default canvas with a default background lets say gray. myapplet.setup();// calls the setup method. /* code for creating and calling a separate thread to handle events. */ // repeatedly calls the draw method until the user closes the canvas window and closes the program while(!windowClosed){ myApplet.draw(); } }
Also the pseudocode(not very "precise", just to give a gist of what I feel) for listening to events which is in the seperate thread according to me should be something like this:
while(!windowClosed){ Event event = listenForEvents(); handleEvent(event); // this accounts for calling keyPressed(). }
Is this the right way of thinking or it all happens in the main thread itself inside the while loop or perhaps there are more than 2 threads involved. I have written what I feel. Any suggestions/ helps would be really appreciated :)