Skip to main content

oval disappreance

No replies
idanaz11
Offline
Joined: 2013-12-08
Points: 0

Ok.
Im new in java. i usually work with vb, so i hope my quetion is not too stupid...
Im trying to make a program thats show some oval on the main form, so i start with a simple form and 1 oval with this code ( working with eclips)

<br />
import java.awt.Color;<br />
import java.awt.Component;<br />
import java.awt.Graphics;<br />
import java.awt.Panel;<br />
import java.awt.Point;</p>
<p>import javax.swing.JFrame;</p>
<p>public class Arc5 extends JFrame {<br />
Point p;<br />
int radius;<br />
Color clr;</p>
<p>Arc5(Point p1,int r1,Color c1){<br />
	p=p1;<br />
	radius=r1;<br />
	clr=c1;</p>
<p>}<br />
	public void paint(Graphics g){<br />
		g.setColor(clr);<br />
		g.fillOval(p.x, p.y, radius, radius);</p>
<p>	}<br />
	/**<br />
	 * @param args<br />
	 */<br />
	public static void main(String[] args) {<br />
		// TODO Auto-generated method stub</p>
<p>Arc5 arc=new Arc5(new Point(50,50),50,Color.GREEN);<br />
arc.setSize(400, 400);<br />
arc.setVisible(true);</p>
<p>	}</p>
<p>}<br />

and i get this beautiful oval....

http://www.java.net/sites/default/files/oval1_0.JPG

now im trying to add another oval, and i dont want to use the same paint function of the main class because i want to add it latter in the program.so if i create another object of Arc5 i will get 2 frames.

so i made a new class like this

<br />
class circle extends Panel{</p>
<p>	Point p;<br />
	int radius;<br />
	Color clr;</p>
<p>	circle(Point p1,int r1,Color c1){<br />
		p=p1;<br />
		radius=r1;<br />
		clr=c1;</p>
<p>	}<br />
		public void paint(Graphics g){<br />
			g.setColor(clr);<br />
			g.drawOval(p.x, p.y, radius, radius);</p>
<p>		}<br />
}<br />

and make a new object in the main function :

circle cr=new circle(new Point(250,250),100,Color.red);
cr.setSize(260, 260);
arc.add(cr);

and now i can see my new oval

http://www.java.net/sites/default/files/oval2_0.JPG

my quetions are :
1. where is my first green oval went ???
2. can i add a new circles to the form without extend the Panel class(i tried it and it wont work) ?

thanks

AttachmentSize
oval1.JPG17.45 KB
oval2.JPG17.4 KB