A First Look at Graphics with the Breadboards Library

The Breadboards library provides a simple way to write java programs with graphical outputs. Breadboard graphics programs can be thought of as functioning much like a felt board, where various shapes can be "stuck to the board". The Breadboard library come with several basic shapes, each of which is represented by a class (whose name is shown in parentheses below):

Just as an example, the program given at the bottom of the page draws the following to the graphics window when run and the button labeled "Btn1" is pressed:

import java.awt.Color;  // this is needed to use the constant "Color.RED" below

import breadboards.Breadboard;
import breadboards.GOval;
import breadboards.GRect;

public class GraphicsDemo extends Breadboard {
   
   public void onButton1Click() {
      
      //construct a rectangle whose upper left corner is at (10,10)
      //and with width 50 and height 100; reference it with a variable
      //named myRect and add it to the graphics window
      GRect myRect = new GRect(10,10,50,100);
      this.add(myRect);
      
      //construct an oval whose upper left corner is at (25,25)
      //and with width 50 and height 100; reference it with a variable
      //named myOval; set things so that when drawn on the screen 
      //its interior will be filled in and the entire oval will be red in color; 
      //and then add it to the graphics window.
      GOval myOval = new GOval(25,25,50,100);
      myOval.setFilled(true);
      myOval.setFillColor(Color.RED);
      this.add(myOval);
   }
   
   public static void main(String[] args) {
      new GraphicsDemo();
   }

}