SUNIL GUTTA

SUNIL GUTTA

  • NA
  • 1k
  • 393.9k

Program explanation please ? very easy

Oct 15 2013 1:21 AM

Hi


import java.awt.*;

import java.awt.geom.*;

import javax.swing.JApplet;

public class geomp extends JApplet

{

Container c;


public void init()

{

c = getContentPane();

c.setBackground(Color.cyan);


}


public void paint (Graphics g)

{

super.paint(g);

Graphics2D g2 = (Graphics2D)g;

Rectangle2D.Float r1 = new Rectangle2D.Float(10f, 10f, 40f, 80f);

Rectangle2D.Float r2 = new Rectangle2D.Float(100f, 10f, 40f, 80f);

BasicStroke b1 = new BasicStroke(7f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

BasicStroke b2 = new BasicStroke (3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);

GradientPaint gp1 = new GradientPaint (100f, 10f, Color.green, 140f, 90f, Color.red, false);


g2.setColor(Color.blue);

g2.setStroke(b1);

g2.draw(r1);

g2.setPaint(gp1);

g2.setStroke(b2);

g2.fill(r2);

g2.setColor(Color.green);

GeneralPath pg1 = new GeneralPath();

pg1.moveTo(30f, 140f);

pg1.lineTo(120f, 120f);

pg1.lineTo(20f, 190f);

pg1.closePath();

g2.setStroke(b1);

g2.draw(pg1);

}



}


Please explain just in brief filling colors, especially I get the length and width but I do not understand x and y of Rectangle2D ; How was it drawn. Thanx


Answers (1)