Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

To create a dummy paint application using Java. Using the application, users can

ID: 3560397 • Letter: T

Question

To create a dummy paint application using Java. Using the application, users can type some text, draw basic shapes such as rectangles and circles, and traces. And the user is able to change the color and the thickness of borders and lines. The requirements are summarized as follows: 1. The application should allow for paint functionality such as drawing rectangles and circles using brushes. a. In case of rectangles, the application should display a dialog to allow the user to enter the height and the width of the rectangle, and also display a color picker using JColorChooser. The coordinates of the upper-left corner is obtained when the user clicks on the drawing surface {the client area of the frame or panel) b. In case of circles, the application should display a dialog to allow the user to enter the diameter of the circle, and also display a color picker using JColorChooser. The coordinates of the center of the circle is obtained when the user clicks on the drawing surface {the client area of the frame or panel)

2. The application can also trace the movements of a mouse by drawing lines connecting the positions of mouse clicks. The application should also display a dialog to allow the user to specify the thickness and the color of the line.
3. The application should provide menus from which users may choose all the preceding options.
4. The application should allow the user to save, and open the document. The file should be a simple text file that stores the attributes of the various shapes or traces.
a. Circle: center, diameter, color e.g. 20, 30, 100, yellow
b. Rectangle: upper-left coordinates, width, height, color e.g. 10, 10, 500, 200, blue
c. Trace: line thickness, color, a sequence of points e.g. 2, green, 10, 10, 12, 13, 20, 30, 45, 55
Bonus option:
1. The application may have a bonus feature that includes text functionality, such as enabling users to change the font name and font size, apply bold or italics, and so on.
2. The data for the text to be saved should be: the starting point, font-style, font-size, bold, italic, and the actual string. E.g. 20, 10, arial, 12, true, false,

Explanation / Answer

hello I tried my level best.. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class paint{ public static void main(String[] args){ Icon iconB = new ImageIcon("blue.gif"); //the blue image icon Icon iconM = new ImageIcon("magenta.gif"); //magenta image icon Icon iconR = new ImageIcon("red.gif"); //red image icon Icon iconBl = new ImageIcon("black.gif"); //black image icon Icon iconG = new ImageIcon("green.gif"); //finally the green image icon //These will be the images for our colors. JFrame frame = new JFrame("Paint It"); //Creates a frame with a title of "Paint it" Container content = frame.getContentPane(); //Creates a new container content.setLayout(new BorderLayout()); //sets the layout final PadDraw drawPad = new PadDraw(); //creates a new padDraw, which is pretty much the paint program content.add(drawPad, BorderLayout.CENTER); //sets the padDraw in the center JPanel panel = new JPanel(); //creates a JPanel panel.setPreferredSize(new Dimension(32, 68)); panel.setMinimumSize(new Dimension(32, 68)); panel.setMaximumSize(new Dimension(32, 68)); //This sets the size of the panel JButton clearButton = new JButton("Clear"); //creates the clear button and sets the text as "Clear" clearButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.clear(); } }); //this is the clear button, which clears the screen. This pretty //much attaches an action listener to the button and when the //button is pressed it calls the clear() method JButton redButton = new JButton(iconR); //creates the red button and sets the icon we created for red redButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.red(); } }); //when pressed it will call the red() method. So on and so on =] JButton blackButton = new JButton(iconBl); //same thing except this is the black button blackButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.black(); } }); JButton magentaButton = new JButton(iconM); //magenta button magentaButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.magenta(); } }); JButton blueButton = new JButton(iconB); //blue button blueButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.blue(); } }); JButton greenButton = new JButton(iconG); //green button greenButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.green(); } }); blackButton.setPreferredSize(new Dimension(16, 16)); magentaButton.setPreferredSize(new Dimension(16, 16)); redButton.setPreferredSize(new Dimension(16, 16)); blueButton.setPreferredSize(new Dimension(16, 16)); greenButton.setPreferredSize(new Dimension(16,16)); //sets the sizes of the buttons panel.add(greenButton); panel.add(blueButton); panel.add(magentaButton); panel.add(blackButton); panel.add(redButton); panel.add(clearButton); //adds the buttons to the panel content.add(panel, BorderLayout.WEST); //sets the panel to the left frame.setSize(300, 300); //sets the size of the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //makes it so you can close frame.setVisible(true); //makes it so you can see it } } class PadDraw extends JComponent{ Image image; //this is gonna be your image that you draw on Graphics2D graphics2D; //this is what we'll be using to draw on int currentX, currentY, oldX, oldY; //these are gonna hold our mouse coordinates //Now for the constructors public PadDraw(){ setDoubleBuffered(false); addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e){ oldX = e.getX(); oldY = e.getY(); } }); //if the mouse is pressed it sets the oldX & oldY //coordinates as the mouses x & y coordinates addMouseMotionListener(new MouseMotionAdapter(){ public void mouseDragged(MouseEvent e){ currentX = e.getX(); currentY = e.getY(); if(graphics2D != null) graphics2D.drawLine(oldX, oldY, currentX, currentY); repaint(); oldX = currentX; oldY = currentY; } }); //while the mouse is dragged it sets currentX & currentY as the mouses x and y //then it draws a line at the coordinates //it repaints it and sets oldX and oldY as currentX and currentY } public void paintComponent(Graphics g){ if(image == null){ image = createImage(getSize().width, getSize().height); graphics2D = (Graphics2D)image.getGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); clear(); } g.drawImage(image, 0, 0, null); } //this is the painting bit //if it has nothing on it then //it creates an image the size of the window //sets the value of Graphics as the image //sets the rendering //runs the clear() method //then it draws the image public void clear(){ graphics2D.setPaint(Color.white); graphics2D.fillRect(0, 0, getSize().width, getSize().height); graphics2D.setPaint(Color.black); repaint(); } //this is the clear //it sets the colors as white //then it fills the window with white //thin it sets the color back to black public void red(){ graphics2D.setPaint(Color.red); repaint(); } //this is the red paint public void black(){ graphics2D.setPaint(Color.black); repaint(); } //black paint public void magenta(){ graphics2D.setPaint(Color.magenta); repaint(); } //magenta paint public void blue(){ graphics2D.setPaint(Color.blue); repaint(); } //blue paint public void green(){ graphics2D.setPaint(Color.green); repaint(); } //green paint }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote