Saturday, 9 June 2018

Paints And Strokes

Paints And Strokes


You are interesting in painting and strokes now you learn how to create good and decorative painting .using java you can make good painting and strokes for using new style and design .here we tell you a simple method how to generate simple painting and strokes from java.


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author rajesh kumar shukla
 */
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Rectangle2D;

public class PaintsAndStrokes extends Frame {
  public static void main( String[] argv ) {
    PaintsAndStrokes myExample = new PaintsAndStrokes( "Paints and strokes" );
  }

  public PaintsAndStrokes( String title ) {
    super( title );
    setSize( 300, 180 );
    addWindowListener( new WindowAdapter() {
      public void windowClosing( WindowEvent we ) {
        dispose();
        System.exit( 0 );
      }
    } );
    setVisible( true );
  }

  public void paint( Graphics g ) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor( Color.red );
    Rectangle2D rect1 = new Rectangle2D.Double( 32, 42, 100, 100 );
    Rectangle2D rect2 = new Rectangle2D.Double( 164, 42, 100, 100 );
    Paint gp = g2d.getPaint();
    g2d.setPaint( new GradientPaint( 32, 42, Color.red, 100, 100, Color.white, true ) );
    g2d.fill( rect1 );
    g2d.setPaint( gp );
    g2d.setStroke( new BasicStroke( 2f, BasicStroke.CAP_ROUND,
                                    BasicStroke.JOIN_ROUND, 3f, new float[]{10f}, 0f ) );
    g2d.draw( rect2 );
  }

}

0 comments:

Post a Comment