email me at borlaj@portlandschools.org
notes previous (09/07/06) submit the dump links  
 

PaintBrush

This is going to be a larger project where you will create a simple paintbrush application, not unlike the one you would find in windows (start-accessories-paint).

Things that are required:

  • colors work
  • at least 4 different painting tools - including a line tool
  • a reset button that will clear the choice
  • these choices above will appear in a different area from the canvas, which will be the drawing region.
  • you are only able to draw in that region
  • somehow show which tool / color is selected

The more sophistication the better. Ideas to add:

  • different size brushes (maybe using slider)
  • more tools (spray paint, polygon, etc)
  • color selected
  • save/import image (see here)

Grading rubric:

16 points:

  • 1/2 point good indenting
  • 1/2 point variables named appropriately
  • 1 point code has your name on it
  • 6 point for tools (1.5 each)
    • -1 if both square and rectangle are always the same size.
  • 2 point for choosing color
  • 2 point for tool drawing only in drawing panel
  • 2 for reset button
  • 1 point showing tool selected (either put it in a textfield or maybe highlight the tool button that is active)
  • 1 point showing which color is selected (either fillRect with the selected color in the toolpanel or maybe highlight the tool button with the color)
  • extra credit for anything above this

Advanced people have to do all of the above, plus at least 2 of the following (2 points each):

  • two more tools
  • color chooser
  • dynamic stuff (like a dynamic rectangle that works
  • fix your line tool so there is no gap when the mouse moves quickly
  • slider for size
  • extra options that are cool
  • more extra options that are cool

 

Starter code

The starter code has panels; The idea here is we are splitting up our applet into sections or panels. The3 panels are drawingPanel, colorPanel and toolPanel. The toolPanel is where you will add each button and color and stuff. The drawing Panel is where the drawing will occur, and colors have suprisingly colors.

 

I would have a global variable selectedColor and selectedTool. 
At beginning I would say:

                Color selectedColor=Color.black;
                String selectedTool="line";
                

Then in wherever you want to paint you would say g.setColor(selectedColor);
T

 

o use the tool, I would say:

if (selectedTool.equals("line"))
	g.drawLine(…..);



Hints
  1. Before you draw, see if you are in the canvas.
  2. Colors
  3. Colorchooser
  4. Set thickness of line: .
  • Graphics2D g2 = (Graphics2D)g;
    g2.setStroke(new BasicStroke(10));
  • //now draw line as normal
  1. Set background of button: paintButton.setBackground(Color.RED); [Mac User- paintButton.setOpaque(true);]
  2. To clear the background of button: paintButton.setBackground(UIManager.getColor( "Button.background" ));

 

 

 

 

 

Mac Users, add this to initialize:

           colorWhiteButton.setOpaque(true);
        colorWhiteButton.setBorderPainted(false);
        colorBlackButton.setOpaque(true);
        colorBlackButton.setBorderPainted(false);
        colorRedButton.setOpaque(true);
        colorRedButton.setBorderPainted(false);
        colorOrangeButton.setOpaque(true);
        colorOrangeButton.setBorderPainted(false);
        colorYellowButton.setOpaque(true);
        colorYellowButton.setBorderPainted(false);
        colorGreenButton.setOpaque(true);
        colorGreenButton.setBorderPainted(false);
        colorBlueButton.setOpaque(true);
        colorBlueButton.setBorderPainted(false);
        colorMagentaButton.setOpaque(true);
        colorMagentaButton.setBorderPainted(false);