|
Replies:
1
-
Last Post:
Aug 16, 2009 7:09 PM
by: tomross
|
Threads:
[
Previous
|
Next
]
|
|
|
|
|
|
adding fillOval to jpanel
Posted:
Mar 31, 2009 4:53 AM
|
|
|
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
|
|
|
|
|
|
|
Re: adding fillOval to jpanel
Posted:
Aug 16, 2009 7:09 PM
in response to: wireoless
|
|
|
Hi,
I haven't looked carefully at your code, but your "Graphics img" seem should be initialized by using getGraphics().
----------------- java sudoku
|
|
|
|
|