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 =650; // Frame width
static int h =400; // Frame height
public static void main(String[] args){
JFrame frame = new JFrame(); // Create a JFrame container
DrawingCanvas canvas = new DrawingCanvas(); // Create a JComponent drawing canvas
frame.getContentPane().setBackground(Color.white); // Set frame background color
frame.setSize(w, h); // Set frame size (width, height)
frame.setTitle("Drawing in Java"); // Set frame title
frame.add(canvas); // Add drawing canvas to the frame
frame.setLocationRelativeTo(null); // Set frame location to center of screen
frame.setVisible(true); // Show frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
protected void paintComponent(Graphics g){// Override paintComponent method
// Create a Graphics2D object instance
Graphics2D g2d =(Graphics2D) g; // Cast g to a 2D graphics object
GradientPaint blueToGreen = new GradientPaint(500,220,(new Color(0x254B32)),650,220, Color.green);
// Apply the gradient to a rectangle
g2d.setPaint(blueToGreen);
g2d.fillRect(520,220,100,1);
}
}
Task Instructions: Write a Java program to create

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!