Java 2D Drawing Application. The application will contain the following elements: a) an Undo button to undo the last shape drawn. b) a Clear button to clear all shapes from the drawing. c) a combo box...

1 answer below »

Java 2D Drawing Application.


The application will contain the following elements:


a) an Undo button to undo the last shape drawn.
b) a Clear button to clear all shapes from the drawing.
c) a combo box for selecting the shape to draw, a line, oval, or rectangle.
d) a checkbox which specifies if the shape should be filled or unfilled.
e) a checkbox to specify whether to paint using a gradient.
f) two JButtons that each show a JColorChooser dialog to allow the user to choose the first and second color in the gradient.
g) a text field for entering the Stroke width.
h) a text field for entering the Stroke dash length.
I) a checkbox for specifying whether to draw a dashed or solid line.
j) a JPanel on which the shapes are drawn.
k) a status bar JLabel at the bottom of the frame that displays the current location of the mouse on the draw panel.
If the user selects to draw with a gradient, set the Paint on the shape to be a gradientof the two colors chosen by the user. If the user does not chose to draw with a gradient, then Paint with a solid color of the 1st Color. The following code can create a gradient paint object:
Paint paint = new GradientPaint(0, 0, color1, 50, 50, color2, true);


To set the stroke for a line to be drawn, you can use the following code:



if (dashCheckBox.isSelected())
{
stroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10, dashLength, 0);
} else
{
stroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
}


Where the first stroke line creates a dashed line and dashLength is a one element float array with the dash length in the first element. The second stroke line creates an undashed line with the line width specified from the GUI.


Note: When dragging the mouse to create a new shape, the shape should be drawn as the mouse is dragged.


A template project has been provided for you in Canvas in Java2DDrawingApplicationTemplate.zip. This project contains a MyShapes hierarchy that is a complete shape hierarchy for drawing a line, rectangle or oval. You must use this MyShapes hierarchy. A template for the Drawing Application Frame is also provided along with a template for the DrawPanel inner class. You do not need to use these templates if you so choose.


In the paintComponent(Graphics g) method of the DrawPanel, to loop through and draw each shape created by the user, you will loop through an ArrayList of MyShapes, that you built, and call the draw(Graphics2D g2d) method for each shape. The draw method is already implemented in the MyShapes hierarchy.


Note: You do not need to create an event handler for each component in the top two lines of the frame. You only need to create event handlers for the buttons. You can get the values out of all the other components in the top two lines, when the user presses the mouse button on the DrawPanel. At that time, you have all the information you need to create a new Myshapes object.



Note: Do not use the NetBeans GUI generator for this assignment.

Answered Same DayNov 11, 2021

Answer To: Java 2D Drawing Application. The application will contain the following elements: a) an Undo button...

Mohd answered on Nov 17 2021
144 Votes
Completed Solution/Java2DDrawingApplicationTemplate/.classpath

    
    
    
Completed Solution/Java2DDrawingApplicationTemplate/.project

     Java2DDrawingApplicationTemplate
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
Completed Solution/Java2DDrawingApplicationTemplate/bin/Feature.class
public synchronized class Feature {
private java.awt.Color color1;
private java.awt.Color color2;
private int length1;
private int length2;
private boolean gradientStyle;
private boolean fillStyle;
private boolean dashStyle;
public void Feature(java.awt.Color, java.awt.Color, boolean, boolean, boolean, int, int);
public java.awt.Color getColor1();
public java.awt.Color getColor2();
public boolean isGradientStyle();
public boolean isFillStyle();
public boolean isDashStyle();
public int getLength1();
public int getLength2();
}
Completed Solution/Java2DDrawingApplicationTemplate/bin/ImplementFeature.class
public abstract synchronized class ImplementFeature implements ShapeImp {
private java.awt.Rectangle rectangleBox;
private Feature feature;
public void ImplementFeature(Feature);
public Feature getFeature();
public abstract java.awt.Shape getShape();
public void setLocPoints(java.awt.Point);
public void setShapeSize(java.awt.Dimension);
public java.awt.Rectangle getDimensions();
public void paint(javax.swing.JComponent, java.awt.Graphics2D);
}
Completed Solution/Java2DDrawingApplicationTemplate/bin/LineShape.class
public synchronized class LineShape extends ImplementFeature {
public void LineShape(Feature);
public java.awt.Shape getShape();
}
Completed Solution/Java2DDrawingApplicationTemplate/bin/OvalShape.class
public synchronized class OvalShape extends ImplementFeature {
public void OvalShape(Feature);
public java.awt.Shape getShape();
}
Completed Solution/Java2DDrawingApplicationTemplate/bin/Paint2D$MenuDisplay$Pointer.class
public synchronized class Paint2D$MenuDisplay$Pointer extends java.awt.event.MouseAdapter {
private ShapeImp shapeDrawable;
private java.awt.Point shapePoint;
public void Paint2D$MenuDisplay$Pointer(Paint2D$MenuDisplay);
public void mousePressed(java.awt.event.MouseEvent);
public void mouseDragged(java.awt.event.MouseEvent);
public void mouseMoved(java.awt.event.MouseEvent);
}
Completed Solution/Java2DDrawingApplicationTemplate/bin/Paint2D$MenuDisplay.class
public synchronized class Paint2D$MenuDisplay extends javax.swing.JPanel implements java.awt.event.ActionListener {
public javax.swing.JComboBox shapeComboBox;
private javax.swing.JButton color1;
private javax.swing.JButton color2;
private javax.swing.JCheckBox checkBox1;
private javax.swing.JCheckBox checkBox2;
private javax.swing.JCheckBox checkBox3;
private javax.swing.JTextField lineWidth;
private javax.swing.JTextField dashLength;
private javax.swing.JLabel label1;
private javax.swing.JLabel label2;
private Paint2D$ShapeDisplay mainPanelDisplay;
private javax.swing.JPanel newpanel;
private javax.swing.JPanel newpanel2;
public void Paint2D$MenuDisplay(Paint2D, Paint2D$ShapeDisplay);
public int getL2();
public int getL1();
protected ShapeImp createDrawable();
public void actionPerformed(java.awt.event.ActionEvent);
}
Completed Solution/Java2DDrawingApplicationTemplate/bin/Paint2D$ShapeDisplay.class
synchronized class Paint2D$ShapeDisplay extends javax.swing.JPanel {
public void Paint2D$ShapeDisplay(Paint2D);
public java.awt.Dimension getPreferredSize();
protected void paintComponent(java.awt.Graphics);
public void addNewShape(ShapeImp);
}
Completed Solution/Java2DDrawingApplicationTemplate/bin/Paint2D.class
public synchronized class Paint2D extends javax.swing.JPanel implements java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener {
javax.swing.JFrame frame;
public static java.util.ArrayList listShapes;
public javax.swing.JButton clearButton;
public javax.swing.JButton undoButton;
private javax.swing.JLabel mouseCoordinate;
public Paint2D$ShapeDisplay displayShape;
public Paint2D$MenuDisplay menuDisplay;
public void Paint2D();
public void init();
public static void main(String[]);
public void mouseMoved(java.awt.event.MouseEvent);
public void mouseClicked(java.awt.event.MouseEvent);
public void mouseEntered(java.awt.event.MouseEvent);
public void mouseExited(java.awt.event.MouseEvent);
public void mousePressed(java.awt.event.MouseEvent);
public void mouseDragged(java.awt.event.MouseEvent);
public void mouseReleased(java.awt.event.MouseEvent);
public void actionPerformed(java.awt.event.ActionEvent);
}
Completed Solution/Java2DDrawingApplicationTemplate/bin/RectangleShape.class
public synchronized class RectangleShape extends ImplementFeature {
public void RectangleShape(Feature);
public java.awt.Shape getShape();
}
Completed Solution/Java2DDrawingApplicationTemplate/bin/ShapeImp.class
public abstract interface ShapeImp {
public abstract void paint(javax.swing.JComponent, java.awt.Graphics2D);
public abstract void setLocPoints(java.awt.Point);
public abstract void setShapeSize(java.awt.Dimension);
public abstract Feature getFeature();
public abstract java.awt.Rectangle getDimensions();
}
Completed Solution/Java2DDrawingApplicationTemplate/src/Feature.java
Completed...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here