So I’m trying to make a drawing for an assignment that includes different shapes. I have the code for the drawing the and the window, but when I run it the only thing that shows up is the JFrame and not the drawing I am trying to display, which in this case is a snowman.
MyFrame.Java This is my code for the drawing and JFrame
import java.awt.;
import javax.swing.;
public class MyFrame extends Main {
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Draw the body of the snowman
g.setColor(Color.WHITE);
g.fillOval(200, 50, 200, 200);
g.fillOval(150, 150, 300, 300);
g.fillOval(100, 300, 400, 400);
// Draw the buttons
g.setColor(Color.BLACK);
g.fillOval(250, 250, 50, 50);
g.fillOval(350, 250, 50, 50);
g.fillOval(300, 350, 50, 50);
// Draw the eyes and mouth
g.fillOval(250, 200, 20, 20);
g.fillOval(350, 200, 20, 20);
g.drawArc(300, 250, 100, 50, 200, 140);
// Draw the arms
g.drawLine(150, 200, 75, 100);
g.drawLine(450, 200, 525, 100);
// Draw the hat
g.setColor(Color.BLACK);
g.fillRect(250, 75, 100, 25);
g.fillRect(275, 25, 50, 50);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("Snowman");
frame.setSize(700, 700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Main.Java This is my other class.
import java.awt.Graphics;
public class Main {
public static void main(String[] args) {
new MyFrame();
}
public void paintComponent(Graphics g) {
// TODO Auto-generated method stub
}
}