Question: using the code I provide and I need the answer excatly matches the picutre ( size doesn't matter ) . / / DrawATrain class /

using the code I provide and I need the answer excatly matches the picutre(size doesn't matter).// DrawATrain class
// for use with Homework 26
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 DrawATrain extends JFrame {
// Define constants
public static final int CANVAS_WIDTH =960;
public static final int CANVAS_HEIGHT =720;
// 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 DrawATrain(){
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.WHITE); // set background color for this JPanel
//** Type your drawing code in here **
//** Stop typing your drawing code in here **
}
}
// 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 DrawATrain(); // Let the constructor do the job
}
});
}
}
using the code I provide and I need the answer

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!