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
Things that are
- colors work
- at least 4 different painting tools - including a line
- 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
- different size brushes (maybe using slider)
- more tools (spray paint, polygon, etc)
- color selected
- save/import image (see here)
- 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
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:
Then in wherever you want to paint you would say g.setColor(selectedColor);
o use the tool, I would say:
- Before you draw, see if you are in the canvas.
- Set thickness of line: .
- Graphics2D g2 = (Graphics2D)g;
- //now draw line as normal
- Set background of button: paintButton.setBackground(Color.RED); [Mac User-
- To clear the background of button: paintButton.setBackground(UIManager.getColor( "Button.background" ));
Mac Users, add this to initialize: