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 wr
Your class DrawPanel
is confined to the scope of your main
method and is not visible to your constructor.
You need to move DrawPanel
out of your main
method, then add it to your JFrame
:
frame.add(panel);
Also, better to call frame.setVisible(true)
after all components have been added.
you're never actually adding the panel to the frame, so it is never visible. you need something like
frame.getContentPane().add( panel );
why are you defining the drawpanel class inside the main method? that's rather odd.