Getting the Dimensions of a Breadboard's Canvas

The dimensions of the canvas (the central drawing area of a breadboard window) are slightly smaller than the dimensions of the breadboard window itself. In particular, one must subtract from the height of the breadboard window both the height of the top (i.e., NORTH) portion of the window where a text area can be found, and the height of the bottom (i.e., SOUTH) portion of the window where the text field and button(s) can be found.

With this in mind, note that one can get the width and height of the canvas by using something similar to the following code -- which places a pink rectangle so that it exactly fills this central drawing area. (When you run this program, you can test that claim by dragging the corner of the window to expand it. You will see the pink rectangle doesn't extend past the original size of the canvas.)

import java.awt.Color;

import acm.breadboards.OneButtonBreadboard;

public class BorderFun extends OneButtonBreadboard{

  public void run() {
    double textAreaPanelHeight = this.getRegionPanel(OneButtonBreadboard.NORTH).getHeight();	
    double textFieldPanelHeight = this.getRegionPanel(OneButtonBreadboard.SOUTH).getHeight();
    //draw a pink rectangle that exactly fills the central drawing area
    GRect rect = new GRect(0,0,499,499-textAreaPanelHeight-textFieldPanelHeight);
    rect.setFillColor(new Color(255,200,200));