Using paintComponent() to draw rectangle in JFrame
问题 I'm trying to create a program that draws shapes (a rectangle on the example below) using JPanel's paintComponent(), but I can't get it to work and can't spot what is wrong. The code is as follows: import javax.swing.*; import java.awt.*; public class RandomRec{ JFrame frame; public void go(){ frame = new JFrame(); frame.setSize(500,500); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawPanel panel = new DrawPanel(); } public static void main (String[] args){