Drawing Shapes in Java Program
Drawing Shapes in Java Program
import java.awt.geom.*;
import javax.Swing.*;
public class DrawTest
{
public Static void main(String args[])
{
JFrame frame=new JFrame("2d shapes");
Container contentPane=frame.getContentPane();
contentPane.add(new DrawPanel());
frame.setSize(200,200);
frame.setLocation(100,200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class DrawPanel extends JPanel
{
public void paintComponents(Graphics g)
{
super.paintCompoent(g);
Graphic2D g2=(Graphic2D)g;
double leftX=40;
double topY=40;
double width=80;
double height=60;
Rectangle2D rect=new Rectangle2D Double(leftX,topY,width,height);
g2.draw(rect);
Ellipse2D ellispe=new Ellipse2D.Double();
ellipse.setFrame(rect);
g2.draw(ellipse);
g2.draw(newLine2D.Double(leftX,topY,leftX+width,topY+height));
double centerX=rect.getCenterX();
double centerY=rect.getCenterY();
double radius=60;
Ellipse2D.circle=new Ellipse2D.Double;
circle.setFrameFromCenter(centerX,centerY,centerX+radius,centerY+radius);
g2.draw(circlce);
}
}
0 coment�rios:
Post a Comment