Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Assignment 5: GUI
Introduction
This assignment tests about the Java GUI knowledge. You are asked to write a graphics object
editor program to complete 3 tasks.
With the program, users can draw line, circle, triangle and quadrilateral. The created graphics can
be selected, then user can move, copy, delete, randomly color the graphics object.
You need to write JavaDoc for all non-private classes and non-private class members.
Here is the detail of 3 tasks:
Task 1: DrawObjectEditor
Create the java file DrawObjectEditor.java as follow:
You need to create graphics objects with the following classes in Java AWT:
java.awt.geom.Line2D
java.awt.geom.Ellipse2D
java.awt.Polygon
You also have to handle mouse events using MouseMotionListener and/or MouseListener.
You can use the contains() method defined in classes Line2D, Ellipse2D and Polygon to check if
the mouse’s position is contained inside the graphics object boundary.
import java.awt.*;
import javax.swing.JFrame;
public class DrawObjectEditor extend JFrame{
}
The DrawObjectEditor is started with a grey background color editor panel of size 400 x 450 as
follow:
You are not required to follow exactly the same position of the JButton objects as in the above
figure, but should look similar to it.
Task 2: Object Creation Function
When the Line button, the Circle button, the Triangle button or the Quadrilateral button is pressed,
the user can create the object in the editor panel and the color of the corresponding button will
change to grey and not clickable before the object is created:
To draw a line, the user clicks the starting point. The starting point then displays a dot. The user
then clicks the end point and the line will be drawn:
Starting Point (x1, y1)
Ending Point (x2, y2)
To draw a circle, the user clicks the center of the circle. The center displays a dot. The user then
clicks the radius to draw a circle:
Center (x1, y1)
Radius (x2, y2)
To draw a triangle, the user clicks the top corner point, bottom left corner point and then the
bottom right corner as follow:
Top left corner (x1, y1)
Bottom right corner (x3, y3)
Bottom left corner (x2, y2)
To draw a Quadrilateral, the user clicks the top left corner point, bottom left corner point, the
bottom right corner and then the top right corner point as follow:
NOTE: You can assume that all objects created by the user will NOT overlapping with each other.
Top left corner (x1, y1)
Bottom right corner (x3, y3)
Bottom left corner (x2, y2)
Top right corner (x4, y4)
Task 3: Select, Move, Delete, Copy and Random Color function
1. When the user presses the Select button, the user can select an object in the editor panel by
clicking the area within the object. The Select button color will change to grey and not clickable
before an object has been selected.
2. When an object has been selected, the color of the selected object border will change to green.
The user can then perform operations such as move or delete. The operation buttons [Move,
Delete, Copy, Random Color] should become clickable.
3. When an object has been selected, the user can press the Move button to move the object by
press and release.