Search code examples
javaswinggraphicsdrawpaintcomponent

Java not drawing desired graphics


This is a pretty simple program that just draws a white rectangle in a pop-up window. The program compiles and runs no problem, and the windoe pops up, but there is nothing in it, it's just grey. Why isn't anything drawing?

import java.awt.*;
import javax.swing.*;

public class DrawPanel extends JPanel {
    public void paintcompnent(Graphics g) {
        int width = getWidth();
        int height = getHeight();

        super.paintComponent(g);
        g.setColor(Color.WHITE);
        g.fillRect(10, 10, 200, 200);
    }

    public static void main(String[] args) {
        DrawPanel panel = new DrawPanel();
        JFrame window = new JFrame();
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.add(panel);
        window.setSize(550,550);
        window.setVisible(true);
    }
}

Solution

  • public void paintcompnent(Graphics g)
    

    Should be

    public void paintComponent(Graphics g)