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

Example of a similar program Creative Drawing: You get a chance to be creative w

ID: 3857599 • Letter: E

Question


Example of a similar program
Creative Drawing: You get a chance to be creative with this assignment. Create a that draws a design or a recognizable drawing. It should include the following .1 * Give the project and file a meaningful name. Use correct capitalization e You should create a drawing. Use at least 3 different graphics throughout your program (class, variables, methods, etc.). statements (drawing a line, rectangle, oval, arc, String, and/or changing color)i your drawing. This should be recognizable drawing. Do not draw random shapes. Do NOT use examples that were given to you in the text or that you r changing color in found on the Internet. Proper indentation should be used throughout program. Comments should be included throughout program to explain your statements You don't have to explain every statement, but explain the statements that you think are important. You should have at least 3 comments in your program not including the comments for your name, date, and description of the program at the top of the program. These comments must be meaningful. . Examples of previous student work: THE DARK KNIGHT By: John Bemenderfer By: Jonathan Romo By: Brett Holman

Explanation / Answer

import java.awt.*; // Using AWT's Graphics and Color
import java.awt.event.*; // Using AWT event classes and listener interfaces
import javax.swing.*; // Using Swing's components and containers

/** Custom Drawing Code Template */
// A Swing application extends javax.swing.JFrame
public class CGTemplate extends JFrame {
// Define constants
public static final int CANVAS_WIDTH = 640;
public static final int CANVAS_HEIGHT = 480;

// Declare an instance of the drawing canvas,
// which is an inner class called DrawCanvas extending javax.swing.JPanel.
private DrawCanvas canvas;

// Constructor to set up the GUI components and event handlers
public CGTemplate() {
canvas = new DrawCanvas(); // Construct the drawing canvas
canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT));

// Set the Drawing JPanel as the JFrame's content-pane
Container cp = getContentPane();
cp.add(canvas);
// or "setContentPane(canvas);"

setDefaultCloseOperation(EXIT_ON_CLOSE); // Handle the CLOSE button
pack(); // Either pack() the components; or setSize()
setTitle("......"); // "super" JFrame sets the title
setVisible(true); // "super" JFrame show
}

/**
* Define inner class DrawCanvas, which is a JPanel used for custom drawing.
*/
private class DrawCanvas extends JPanel {
// Override paintComponent to perform your own painting
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g); // paint parent's background
setBackground(Color.BLACK); // set background color for this JPanel

// Your custom painting codes. For example,
// Drawing primitive shapes
g.setColor(Color.YELLOW); // set the drawing color
g.drawLine(30, 40, 100, 200);
g.drawOval(150, 180, 10, 10);
g.drawRect(200, 210, 20, 30);
g.setColor(Color.RED); // change the drawing color
g.fillOval(300, 310, 30, 50);
g.fillRect(400, 350, 60, 50);
// Printing texts
g.setColor(Color.WHITE);
g.setFont(new Font("Monospaced", Font.PLAIN, 12));
g.drawString("Testing custom drawing ...", 10, 20);
}
}

// The entry main method
public static void main(String[] args) {
// Run the GUI codes on the Event-Dispatching thread for thread safety
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new CGTemplate(); // Let the constructor do the job
}
});
}
}

Dr Jack
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote