COMP2396讲解、Java编程语言调试、讲解programming、Java语言讲解

- 首页 >> Java编程
COMP2396 Object-oriented programming and Java
Assignment 5: GUI
Due date: 15 Apr, 2020 23:59
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.
4. When an object has been selected, user can click the Delete button to delete the selected object
in the editor panel.
5. When an object has been selected, the user can press the Copy button to copy the selected
object. Your program should display the copied object near the original object (No strict
requirement for the position of it, just don’t make it too far away). The copied object should
just like other objects, and can be selected, moved, deleted, copied and colored.
6. When an object has been selected, user can click the Random Color button to fill the
geometric object with random color. The colored object should just like other objects, and can
be selected, moved, deleted, copied and re-colored.
Submission
⚫ Please submit your files to Moodle.
⚫ Make sure you have submitted .java files but not .class files.
⚫ You may create additional classes to complete the tasks.
⚫ Late submission is not allowed.
Grading
➢ 95% marks are given to the functionality of your program.
5% --- GUI
90% (10% for each function):
1.Draw Line / 2.Draw Circle / 3.Draw Triangle / 4.Draw Quadrilateral / 5.Select
function / 6.Move function / 7.Delete function / 8.Copy function / 9.Random Color
function
➢ 5% marks are given to your JavaDoc.
A complete JavaDoc includes documentation of every classes, member fields and methods that are
not private.

站长地图