|
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). You will have till Tuesday (11/29) beginning
of class.
Things that are
required:
- atleast 6 different colors or use ColorChooser
- at least 3 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.
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:
14 points:
- 1 points comments.
- 1 points good indenting
- 1 points variables named appropriately
- 3 point for tools (1 each)
- 1 point for choosing color
- 2 point for enough color options
- 1 point for tool drawing only in drawing panel
- 1 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)
- 1 for good placement of objects - looks nice
- extra credit for anything above this
|
 |
Starter code.
The starter code has panels; The idea here is we are splitting up our applet into sections or panels. The 2 panels are drawingPanel and toolPanel. The toolPanel is where you will add each button and color and stuff. The drawing Panel is where the drawing will occur.
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
- Before you draw, see if you are in the canvas.
- If you want to use an image for a button, you could draw your
buttons, harder? Or get an image and use the code below (the image
needs to be in the same directory):
JButton button = new JButton( new ImageIcon("redCircle.jpg"));
- Colors
- Colorchooser
- Set thickness of line: .
- Graphics2D g2 = (Graphics2D)g;
g2.setStroke(new BasicStroke(10));
- //now draw line as normal
- Set background of button: paintButton.setBackground(Color.RED); [Mac User-
paintButton.setOpaque(true);]
- To clear the background of button: paintButton.setBackground(UIManager.getColor( "Button.background" ));
Hi flyers; you are required (yes required, but thats not fair
you say. Well no its not. No one ever said life is fair. Im going
to report you to the school board. Thats okay, Im tenured, its really
hard to fire me. I hate you mr borland. I know. Mr. Borland lives
on your tears.
- you must have 5 tools
- fix your line tool so there is no gap when the mouse moves quickly
- more to come...
|