email me at

notes previous (14/<14) submit the dump links  

Basic drawing activity


Sorry I couldnt be there today. I thought it would be good practice for you to do another drawing activity (we soon are going to be doing graphical stuff). Copy the code below in to a new class in BlueJ. Compile and run it (to run it, right click method startDrawing()

You are going to write the code in paint to draw a scene. This time instead of using triangles and circles (like before), you have a huge library called graphics. Look at the api here - on this page go to methods. You will see hundreds like drawLine or fillOval).

I want you to create a drawing that looks like something (a person, a house), I want at least 3 colors and shapes. I also want you to draw some text on it. Submit it online.

import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;

public class Drawing extends JFrame{

    public void paint(Graphics g) {
        g.fillRect(0, 0, 200, 100);
        g.drawString("Sample Drawing", 20, 20);
        g.drawString("created by Borland", 200, 400);

    public Drawing(){
        JPanel panel=new JPanel();

    public static void startDrawing(){
        Drawing d=new Drawing();