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

Create an application that enables the user to paint a picture. The user should

ID: 3644130 • Letter: C

Question

Create an application that enables the user to paint a picture. The user should be able to choose the shape to draw, the color in which the shape should appear and whether the shape should be filled with color. Use JRadioButton-s to select the type of a shape (which should be oval, or rectangle, or a line) and JCheckBox to determine if the shape should be filled with color. Use JComboBox to choose the color of the shape. To determine location of the shape, implement the method mousePressed of the MouseAdapter to set the first corner of the shape and the method mouseReleased of the MouseAdapter to set the second corner of the shape (you can use methods abs and min of the class Math computing, respectively, absolute value to determine the width and the height of the shape, and minimum to determine the top corner point of the shape). Use different frames for painting and tools. Use panels as appropriate.
pls program in java netbeans and pls show the ouput.

Explanation / Answer

DrawIII.java // Program draws different shapes with the mouse import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DrawIII extends JFrame { private int topX, topY; private int width, height, shape; private int bottomX, bottomY; protected JLabel status; public static final int CIRCLE = 0, OVAL = 1, LINE = 2, RECT = 3; public DrawIII() { super( "DrawIII" ); topX = topY = 0; status = new JLabel(); getContentPane().add( status, BorderLayout.SOUTH ); addMouseListener( new MouseHandler( this ) ); addKeyListener( new KeyHandler( this ) ); setSize( 300, 150 ); show(); } public int getTopX() { return topX; } public int getTopY() { return topY; } public int getBottomX() { return bottomX; } public int getBottomY() { return bottomY; } public void setTopX( int x ) { topX = x; } public void setTopY( int y ) { topY = y; } public void setBottomX( int x ) { bottomX = x; } public void setBottomY( int y ) { bottomY = y; } public void setWidth( int w ) { width = w; } public void setHeight( int h ) { height = h; } public void paint( Graphics g ) { if ( shape != LINE ) { topX = Math.min( topX, bottomX ); topY = Math.min( topY, bottomY ); } switch ( shape ) { case CIRCLE: g.drawOval( topX, topY, width, width ); break; case OVAL: g.drawOval( topX, topY, width, height ); break; case LINE: g.drawLine( topX, topY, bottomX, bottomY ); break; case RECT: g.drawRect( topX, topY, width, height ); break; } } public void setShape( int s ) { shape = s; } public static void main( String args[] ) { DrawIII app = new DrawIII(); app.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); } } class MouseHandler extends MouseAdapter { private DrawIII draw; public MouseHandler( DrawIII d ) { draw = d; } public void mouseReleased( MouseEvent e ) { draw.setBottomX( e.getX() ); draw.setBottomY( e.getY() ); draw.setWidth( Math.abs( draw.getTopX() - draw.getBottomX() ) ); draw.setHeight( Math.abs( draw.getTopY() - draw.getBottomY() ) ); draw.repaint(); } public void mousePressed( MouseEvent e ) { draw.setTopX( e.getX() ); draw.setTopY( e.getY() ); } } class KeyHandler extends KeyAdapter { private DrawIII draw; public KeyHandler( DrawIII d ) { draw = d; } public void keyTyped( KeyEvent e ) { int s = DrawIII.CIRCLE; switch ( e.getKeyChar() ) { case 'c': case 'C': s = DrawIII.CIRCLE; draw.status.setText( "Circle" ); break; case 'o': case 'O': s = DrawIII.OVAL; draw.status.setText( "Oval" ); break; case 'r': case 'R': s = DrawIII.RECT; draw.status.setText( "Rectangle" ); break; case 'l': case 'L': s = DrawIII.LINE; draw.status.setText( "Line" ); break; default: draw.status.setText( "Circle" ); break; } draw.setShape( s ); } }

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