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

Please show the full java code for blew \"\"statement, which can run in the ecsp

ID: 3826821 • Letter: P

Question

Please show the full java code for blew ""statement, which can run in the ecsplise, and snapshot of out. thank you very much.
"Take the code for the various graphics
Show a triangle, square, rectangle and circle in one frame or panel and fill the geometric shapes with color:
Triangle – red
Square – yellow
Rectangle – blue
Circle – green" Please show the full java code for blew ""statement, which can run in the ecsplise, and snapshot of out. thank you very much.
"Take the code for the various graphics
Show a triangle, square, rectangle and circle in one frame or panel and fill the geometric shapes with color:
Triangle – red
Square – yellow
Rectangle – blue
Circle – green" Please show the full java code for blew ""statement, which can run in the ecsplise, and snapshot of out. thank you very much.
"Take the code for the various graphics
Show a triangle, square, rectangle and circle in one frame or panel and fill the geometric shapes with color:
Triangle – red
Square – yellow
Rectangle – blue
Circle – green"

Explanation / Answer

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class ColorShape {

    private JFrame frame;
    private JPanel pane;

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new ColorShape().createAndShowGui();
            }
        });
    }

    public void createAndShowGui() {
        frame = new JFrame(getClass().getSimpleName());
        pane = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g); //ALWAYS call this method first!
    g.drawRect(10, 10, 50, 50); //Draws square
    g.setColor(Color.yellow);      //Fills a square
    g.drawRect(10, 75, 100, 50); //Draws rectangle
    g.setColor(Color.blue);      ; //Fills a rectangle
    g.drawPolygon(new int[] {35, 10, 60}, new int[] {150, 200, 200}, 3); //Draws triangle
    g.setColor(Color.red); //Fills triangle
    g.drawOval(10, 20, 5, 5);
                g.setColor(Color.green);
    
    g.dispose();
            }

            @Override
            public Dimension getPreferredSize() {
                return new Dimension(300, 300);
            }
        };

        frame.add(pane);
        frame.pack();
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}