Saturday, April 12, 2014

2D Graphics with Java


import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class drawing2 extends JFrame
{
public drawing2()
{
super(" FAHIM");
setBackground(Color.blue);
setSize(600,600);
setVisible(true);
}
public void paint(Graphics g)
{
Graphics2D g2d=(Graphics2D)g;
Color c1 = new Color(255,175,175);
Color c2 = new Color(255,0,0);
g2d.setPaint(new GradientPaint(5,30,c1,35,100,c2,true));
g2d.setStroke(new BasicStroke(4.0f));
g2d.fill(new Ellipse2D.Double(50,50,50,50));
Color c3 = new Color(0,0,255);
Color c4 = new Color(255,0,0);
g2d.setPaint(new GradientPaint(5,30,c3,35,100,c4,true));
g2d.setStroke(new BasicStroke(4.0f));
g2d.fill(new Ellipse2D.Double(75,75,100,75));
g2d.setPaint(Color.red);
g2d.setStroke(new BasicStroke(6.0f));
g2d.draw(new Line2D.Double(10,75,50,60));
}
public static void main(String args[])
{
drawing2 d=new drawing2();
d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}