The Source for Java Technology Collaboration

Home » java.net Forums » JDK » JCK Forum

Thread: adding fillOval to jpanel

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 1 - Last Post: Aug 16, 2009 7:09 PM by: tomross Threads: [ Previous | Next ]
wireoless

Posts: 1
adding fillOval to jpanel
Posted: Mar 31, 2009 4:53 AM
 
  Click to reply to this thread Reply

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

tomross

Posts: 1
Re: adding fillOval to jpanel
Posted: Aug 16, 2009 7:09 PM   in response to: wireoless
 
  Click to reply to this thread Reply

Hi,

I haven't looked carefully at your code, but your "Graphics img" seem should be initialized by using getGraphics().



-----------------
java sudoku




 XML java.net RSS