CSC 012

Introduction to Computer Science

Summary of 2/20 Lecture

In this class, the authors provide a drawing pad on which we can construct lines, rectangles, circles, ovals, and do other interesting graphical things.  You can discover the functionality of their class by clicking on:  DrawingBox class.

//File:    Play.java
import CSLib.*;
import java.awt.*;
public class Play
{
    public static void main (String [] args)
    {
        DrawingBox pad = new DrawingBox ("Fun & games with shapes");
       
        pad.setSize (400, 400);
       
        pad.drawLine (0 , 0 , 100 , 100); //Draws a line from (0,0) to (100,100)
       
        pad.drawRect (100, 100, 100, 50); //Draw a rectangle whose upper left hand corner is at (100,100)
                        //with width=100 pixels and height=50 pixels
       
        //Dip our brush into the blue paint can
        pad.setColor (Color.BLUE);
        pad.fillRect (250, 100, 100, 50); //Fill a rectangle whose upper left hand corner is at (250,100)
                        //with width=100 pixels and height=50 pixels
       
        pad.setColor (Color.RED);
        pad.fillCircle (225, 50, 25); //Fill a circle with center at (225, 50) with radius 25
       
        pad.setColor (Color.CYAN);
        pad.fillOval ( 213, 175, 25, 50); //Fill an oval inscribed inside a rectangle whose upper
                        //left hand corner is at (213, 175) with width=25 pixels
                        //and height=50 pixels
    }
}
}

wpe43.jpg (11971 bytes)

 


Lab Exercise.  Draw the Olympic Logo with (from left to right) blue, black, red, yellow, and green circles as shown.  For a little extra pizaaz, write "Olympic Logo" underneath.  Consult the documentation for the DrawingBox class to find the appropriate methods.  If you want to check your work with my code, just take a look at Olympic.java.

wpe42.jpg (11408 bytes)


Back to CSC 012 Home Page