Question: Task Instructions: Write a Java program to create a drawing that combines all the shapes you learnt in this lab. i want graphical design can
Task Instructions:
Write a Java program to create a
drawing that combines all the shapes
you learnt in this lab.
i want graphical design can be as
simple as the given examples or as
creative as you want it to be house, a tree and starts
the code must be like this way for example:import java.awt.; For the Color & Graphics
import javax.swing.;
public class DrawingCanvas extends JComponent
static int w ; Frame width
static int h ; Frame height
public static void mainString args
JFrame frame new JFrame; Create a JFrame container
DrawingCanvas canvas new DrawingCanvas; Create a JComponent drawing canvas
frame.getContentPanesetBackgroundColorwhite; Set frame background color
frame.setSizew h; Set frame size width height
frame.setTitleDrawing in Java"; Set frame title
frame.addcanvas; Add drawing canvas to the frame
frame.setLocationRelativeTonull; Set frame location to center of screen
frame.setVisibletrue; Show frame
frame.setDefaultCloseOperationJFrameEXITONCLOSE;
@Override
protected void paintComponentGraphics g Override paintComponent method
Create a GraphicsD object instance
GraphicsD gd GraphicsD g; Cast g to a D graphics object
GradientPaint blueToGreen new GradientPaintnew ColorxB Color.green;
Apply the gradient to a rectangle
gdsetPaintblueToGreen;
gdfillRect;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
