Lab 14: Graphical User Interfaces: Mouse interaction, JPanels etc.

Part 1

Develop a Java program with the user interface displayed here. The user interacts with the user interface by entering desired dimensions in the two textFields. The user then clicks the Draw button, and finally clicks on the lower blue panel. Your software then

Clicking on the EXIT button terminates the program.

Once the above task is completed,

Here is a partial solution.

Part 2

Declare an array of eight different Quadrilaterals, created in Lab 13. You will have to extend the Quadrilateral class with java.awt.Polygon and in each constructor add the following points:
 
Quadrilateral Kite Trapezoid Isoceles
Trapezoid
Parallelogram Rhombus Rectangle Square
addPoint(0, 5);
addPoint(10, 0);
addPoint(20, 0);
addPoint(15, 15);
npoints = 0;
addPoint(0, 7);
addPoint(7, 0);
addPoint(14, 7);
addPoint(7, 20);
npoints = 0;
addPoint(0, 0);
addPoint(30, 0);
addPoint(20, 20);
addPoint(5, 20);
npoints = 0;
addPoint(0, 0);
addPoint(30, 0);
addPoint(20, 20);
addPoint(10, 20);
npoints = 0;
addPoint(0, 0);
addPoint(30, 0);
addPoint(35, 20);
addPoint(5, 20);
npoints = 0;
addPoint(0, 0);
addPoint(30, 5);
addPoint(30, 35);
addPoint(0, 30);
npoints = 0;
addPoint(0, 0);
addPoint(30, 0);
addPoint(30, 20);
addPoint(0, 20);
npoints = 0;
addPoint(0, 0);
addPoint(20, 0);
addPoint(20, 20);
addPoint(0, 20);

In your DrawPad class  add a method to instantiate the array of eight. Add a menu item to select a particular Quadrilateral (or draw rectangle per Part 1)and use this index to

//place quadrilateral in desired location
quad[index].translate(e.getX(), e.getY());
//draw the quadrilateral
g.drawPolygon(quad[index]);
//rezero its bounding rectangle coordinates
quad[index].translate(-(int)(quad[index].getBounds().getX()), -(int)(quad[index].getBounds().getY()));
 

Email your zipped project folder as an attachment.


Based on Dr. Narayan's Lab 7 , Modified by Jack Tompkins