<< Chapter < Page | Chapter >> Page > |
As I mentioned above, the default behavior of the sketch is to call the setup method once and to repeatedly call the draw method until the sketch is terminated, regardless of whether or not the setup and draw methods are overridden. If these methods are not overridden, the sketch will produce an output similar to thatshown in Image 1 .
As you will see later, for the sketch shown in Image 2 , the framework has been extended by overriding the setup and draw methods, and by defining a new class named Car . The code for the class named Car is on the hidden tab named Car in Image 2 and is also shown in Listing 1 .
While we can extend the Processing framework by overriding methods, defining new methods, defining new classes, etc., we cannot, by default, modify theframework code.
Without seeing the source code, it appears that when we click the Run button in Java mode, the Processing framework:
We can
Programs or sketches that we write to run under the Processing framework must be compatible with the behavior described above.
Now it's time to put the theory aside and take a look at an actual sketch.
Listing 1 shows the definition of a class named Car . This class is defined on the hidden tab in Image 2 .
Listing 2 shows the definition of the class named Cars in the leftmost tab of Image 2 . I am repeating it here so that you can copy and paste it into your PDE.
You might think of the class that is defined in Listing 2 as the driver class. You will see later that it is a subclass of the Processing class named PApplet .
When we create a new sketch, this class has a default name something like sketch_130223a .. We can change the name of the class when we select Save or Save As... from the File menu of the PDE.
Saving the sketch causes a sketchbook folder to be created containing a file with a name like sketch_130223a.pde , or whatever name we specify. The name of the sketchbook folder is the same as the nameof the class.
For the case of Image 2 , the sketchbook folder is named Cars and the file is named Cars.pde . (The file named Cars.pde is simply a text file containing Java source code. If you wereworking outside the PDE, you could name it Cars.java.)
Notification Switch
Would you like to follow the 'The processing programming environment' conversation and receive update notifications?