Starting from:

$29.99

Simple windowed Paint application_Project 1 Solution

Java Paint Application

 

For your first project you will be programming a simple windowed Paint application. This will require use of basic game framework and keyboard and mouse input.

 

Requirements

 

Application

The application must be windowed with a resolution of 1280x720. The window should have the title of “Java Paint”. A custom cross-hair cursor must be drawn, hide the default cursor.

 

Tools

Your paint application must have the functionality of the follow tools:

Line Tool – User selects point pairs with left mouse click, draws line of the selected color using points

 

Rectangle Tool – User selects point pairs with left mouse click, draws rectangle of selected color using points. Note that the user must be able to select the points in any order, not necessarily the “top left” first.

 

Poly-line Tool – User selects a series of points with left mouse click, lines are drawn from one to the next. A right mouse click will stop the current line series. While the Poly-line Tool is in the process of selecting points do not allow the user to change colors. They can however change colors between series of lines.

 

Free Draw Tool – User can hold left mouse button down to draw a continuous line.

 

Real-time Tool Usage – As the tool is being used, a real-time preview must be provided. For example, if the Line Tool is selected, after the first point is entered a line is drawn to the current mouse position to show what the line would look like if the second point were to be selected. This behavior applies to the Line Tool, Rectangle Tool, and Poly-line Tool.

 

Colors

The user can select one of four colors, Blue, Red, Green, and Black

 


Tool and Color Selection

Your application must provide a simple on screen “menu” where the user can click on a set of visual tool and color representations. Clicking on these areas will change the current tool/color. Do not allow the menu to be drawn upon.

 

They may also change the tool/color using the mouse scroll wheel. Scrolling the wheel towards the user will cycle through colors, away from the user will cycle through tools.

 

Selected Tool and Color

The color of the cursor must be the same as the currently selected color. In the menu denote the currently selected tool in some way. This can be done by graying out the unselected tools or some other mechanism.

 

Clearing the Drawing

All drawing can be cleared by the user pressing the ‘C’ key on the keyboard.

 

Example Application



Starting State

 



Color changed to Blue, note cursor color change

 



Poly-line selected, note selected tool is darker in menu to denote it is current tool



Drawing does not interfere with menu

 



Drawing cleared, Line tool selected, only selected first point, note line drawn to current cursor position



Cursor moved, line updated in real-time

 

Graphics methods

The following methods belonging to the Graphics class will be helpful. Look up documentation to see full usage. There are some others that may be of help, these are what is probably necessary at a minimum.

drawLine(int x1, int y1, int x2, int y2)

drawRect(int x, int y, int width, int height)

fillRect(int x, int y, int width, int height)

setColor(Color c)

 


ColorPoint

The SimpleMouseExample looked at in class and in the text was a simple free draw. However only one color was ever used; when the color was changed the color of everything changed. This is not the functionality required here. The color of each drawn entity must be stored so the color can be changed before it is rendered. The following is a handy class, ColorPoint, that inherits from Point and adds an additional Color data member. This way every point that is stored also has color data. Feel free to use it.

 

import java.awt.Color;

import java.awt.Point;

 

public class ColorPoint extends Point {

     public Color color;

 

     public ColorPoint(Point p, Color c)

     {

           super(p);

           color = c;

     }

}

 

Application Design

Name your application (the file that has main) Paint so I know where to start execution.

 

You can base your application upon the discussed examples, I suggest starting with RelativeMouseExample for your Frame. The RelativeMouseInput class should be usable as is.

 

Be sure to plan out classes. Do not put all functionality in your Frame class, this will make things very difficult to code/read/debug. I would suggest at the very least creating a class for each of the tools, such that their behavior is encapsulated and easily called upon.

 

Divide your classes up into logical packages.

 

Your submission must include a document that explains your class design. List the classes created, their purpose, and how they are used. Discuss the packages you created and why.

More products