These are the files. I have set JFrame to be visible, and have added JPanel to it, but still, the code only shows the window without anything in it.
import java.util.List;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.Collections;
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(350, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("My Empty Window");
frame.setVisible(true);
DrawingPanel panel = new DrawingPanel();
frame.add(panel);
frame.setVisible(true);
}
-------------DRAWINGPANEL FILE-------------------
import java.awt.Graphics;
import javax.swing.JPanel;
public class DrawingPanel extends JPanel {
public void painting(Graphics pen) {
pen.drawRect(50, 50, 20, 20);
pen.drawRect(100, 50, 40, 20);
pen.drawOval(200,50,20,20);
pen.drawOval(250, 50, 40, 20);
pen.drawString("Square", 50, 90);
pen.drawString("Rectangle", 100, 90);
pen.drawString("Cirlce", 200, 90);
pen.drawString("Oval", 250, 90);
pen.fillRect(50, 100, 20, 20);
pen.fillRect(100, 100, 40, 20);
pen.fillOval(250, 100, 20, 20);
pen.fillOval(250, 100, 40, 20);
pen.drawLine(50, 150, 300, 150);
pen.drawArc(50, 150, 200, 100, 0, 180);
pen.fillArc(100, 175, 200, 75, 90, 45);
}
}