Tuesday, October 19, 2010










/*This is a program used to produced a HOUSE and g2d.fillRect() is a method.*/
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TransparentRectangles4 extends JPanel
{
public void paint (Graphics g)
{
  super.paint(g);
  Graphics2D g2d=(Graphics2D)g;
   g2d.setColor(Color.BLUE);
 
// for (int i=1; i <= 10; i++)
  {
 // g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,i * 0.1f));
 // g2d.fillRect(50 * i,20,40,40);
  g2d.fillRect(200,300,300,300);
 g2d.setColor(Color.BLUE);
 g2d.fillRect(100,800,100,200);
g2d.drawLine(160,350,350,100);
g2d.drawLine(345,90,538,355);


  }
}
 
public static void main(String[]args)
  {
  JFrame frame =new JFrame("Transparent Rectangles");
  frame.add(new TransparentRectangles4());
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(590,120);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
     }
}   









/*This is a program used to produce a CAR and a g2d.fillPolygon() is a method.*/
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TransparentRectangles3 extends JPanel
{
public void paint (Graphics g)
{
  super.paint(g);
  Graphics2D g2d=(Graphics2D)g;
  g2d.setColor(Color.BLUE);
 
// for (int i=1; i <= 10; i++)
  {
 // g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,i * 0.1f)
g2d.setColor(Color.BLUE);
 int x[]={300,600,700,800,800,300,300};
 int y[]={200,200,300,300,400,400,200};
 g2d.fillPolygon(x,y,7);
 g2d.fillOval(400,350,100,100);
 g2d.fillOval(700,350,100,100);
g2d.setColor(Color.GREEN);
 g2d.fillOval(425,375,50,50);
 g2d.fillOval(725,375,50,50);


  }
}
 
public static void main(String[]args)
  {
  JFrame frame =new JFrame("Transparent Rectangles");
  frame.add(new TransparentRectangles3());
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(590,120);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
     }
}   









/*This is a program used to produced My Star and g2d.fillPolygon() is a method.*/
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Font;
import java.awt.color.ColorSpace;

public class Mystar extends JPanel{

 public void paint(Graphics g){
  super.paint(g);
 
  Graphics2D g2d = (Graphics2D)g;
  int x[]={55,67,109,73,83,55,27,37,1,43};
  int y[]={0,36,36,54,96,72,96,54,36,36};
  g2d.fillPolygon(x,y,10);

 }

 public static void main(String[] args){


  JFrame frame = new JFrame("My Star");
  frame.add(new Mystar());
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(300,200);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
 }
   }
/*This is a program used to produce My FLOWER and g2d.fillOval() is a method.*/
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Font;
import java.awt.color.ColorSpace;

public class MyFlower extends JPanel{

 public void paint(Graphics g){
  super.paint(g);
 
  Graphics2D g2d = (Graphics2D)g;



 g2d.setColor(Color.MAGENTA);
 g2d.fillOval(500,200,70,200);
 g2d.fillOval(500,400,70,200);
 g2d.fillOval(540,365,200,70);
 g2d.fillOval(330,365,200,70);
 g2d.setColor(Color.GREEN);
 g2d.fillOval(505,380,50,50);
 }

 public static void main(String[] args){


  JFrame frame = new JFrame(" MY FLOWER");
  frame.add(new MyFlower());
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(1000,700);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
  }
     }