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

IN JAVA // I’m using the * notation here for imports since you may use many clas

ID: 3818986 • Letter: I

Question

IN JAVA

// I’m using the * notation here for imports since you may use many classes from

// these packages

import javax.swing.*;

import java.awt.*;

import java.awt.geom.*;

public class ExperimentWithGraphics extends JPanel

{

       // You may change this constant

       private static final int SIZE = 300;

       public static void main(String[] args)

       {

             // You may change the parameters in the code below a little,

// but proceed with extreme caution. Do not reorder the methods.

             JFrame frame = new JFrame("Line");

             JPanel panel = new ExperimentWithGraphics();

             frame.setSize(SIZE,SIZE);

             frame.getContentPane().add(panel, BorderLayout.CENTER);

              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      

             frame.setVisible(true);

       }

      

       // Do not change this method name or parameters

       public void paintComponent(Graphics g)

       {

             // Do not change the next two lines of code

             super.paintComponent(g);

             Graphics2D g2d = (Graphics2D) g;

            

             // This is where your code should go

             Line2D.Double line = new Line2D.Double(0, 0, SIZE, SIZE);

             g2d.setColor(Color.BLACK);

             g2d.draw(line);

             // Don’t change anything after this

       }

}

To draw a picture in Java, you have to construct an object of the proper type in 2D, then select a color for drawing, and then draw the object. The process is shown above in the last three lines of the paintComponent() method.   The names of the classes that are appropriate to use are given in the objectives. Choose them strategically to make a drawing.

Explanation / Answer

I went through the code it is fine. Could you please eloborate more what exactly you are trying to do if poosible could you please share the screenshot.