Skip to main content

adding fillOval to jpanel

No replies
wireoless
Offline
Joined: 2009-03-31
Points: 0

Hi

First time post here so sorry if this is the wrong place to put this, but i really could do with some help.

im trying to add a filled oval to a JPanel, without creating a 2nd class which i extend.

i have created the GUI which appears fine, but i not able to add the oval to a JPanel.

this is my code.

public class test
{
private JFrame newFrame = new JFrame("Test Circle");
private JPanel newPanel = new JPanel();
private JPanel newPanel2 = new JPanel();
private JTextField text = new JTextField("test field");;
private Graphics img;

/**
* Constructor for objects of class test
*/
public test()
{
newFrame.setPreferredSize(new Dimension(400, 400));
newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = newFrame.getContentPane();
content.setLayout(new GridLayout());

newPanel.setLayout(new GridLayout());
content.add(newPanel, BorderLayout.CENTER);
newPanel.add(text);
img.fillOval(60,60,60,60);
content.add(img);

newFrame.setVisible(true);
newFrame.pack();

}

i always seem to get a NullPointerException at the line img.fillOval(60,60,60,60);
if you could point me in the right direction that would be awesome.

i really would like to know how to do this with out having to put the shape in to a seprate class and creating an object of that class

thank
Wire