Here\'s my simple code. I don\'t really know how to add a drawn oval to a JPanel
. I did some paintings before, but I have never used the constructor so I don\'t hav
The basic structure of your code is wrong. The Buffer class should not be creating a frame. The Buffer class should just be used for painting. The code should be something like:
public static void main(String args[])
{
Buffer oval = new Buffer();
oval.setBackground(Color.RED);
JFrame frame=new JFrame();
frame.add( oval );
frame.setSize(500,500);
frame.setVisible(true);
}
Make sure you invoke super.paintComponent() (without the "s"). You should also be overriding the getPreferredSize()
method to set the size of your custom component. Read the Swing tutorial on Custom Painting for more information and a better example.