Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Show Stroke with Effect 
 

The interface Stroke gives the stylish way of representing the outlines. To show the effect, class GradientPaint is used which fills the specified figure in a color gradient pattern. The class Rectangle2D provides the rectangle figure.

 

Show Stroke with Effect

                         

This section illustrates you how to show stroke with effect.

The interface Stroke gives the stylish way of representing the outlines. To show the effect, class GradientPaint is used which fills the specified figure in a color gradient pattern. The class Rectangle2D provides the rectangle figure.

Following code shows the simple rectangle filled with color gradient pattern:

g2d.setPaint(gradientPaint);
g2d.fill(rectangle);

Following code shows the stroke inside the rectangle:

rectangle.setFrame(p + 90, q, width, height);
g2d.setPaint(gradientPaint);
g2d.setStroke(new BasicStroke(10));
g2d.draw(rectangle);

Following code strokes with gradient:

rectangle.setFrame(p + 180, q, width, height);
g2d.setPaint(Color.black);
g2d.draw(rectangle);

The method setFrame() sets the size of the rectangle. The setPaint(gradientPaint) paints the rectangle in a gradient pattern. The method setStroke() sets the stroke settings for the Graphics2D context, when you draw the shape. The integer value passed into the constructor of class BasicStroke represents the thickness of the outline.

Here is the code of EffectsOfStroke.java

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public class EffectsOfStroke extends JPanel{
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    double p = 12, q = 45, width = 65, height = 65;
    Rectangle2D rectangle = new Rectangle2D.Double(p, q, width, height);
    GradientPaint gradientPaint= new GradientPaint(6565, Color.red,
      
9090,Color.cyan, true);
    g2d.setPaint(gradientPaint);
    g2d.fill(rectangle);
    rectangle.setFrame(p + 90, q, width, height);
    g2d.setPaint(gradientPaint);
    g2d.setStroke(new BasicStroke(10));
    g2d.draw(rectangle);
    rectangle.setFrame(p + 180, q, width, height);
    g2d.setPaint(Color.black);
    g2d.draw(rectangle);
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame("Show Effect");
    frame.getContentPane().add(new EffectsOfStroke());
    frame.setSize(350200);
    frame.show();
  }
}

Output will be displayed as:

Download Source Code

                         

» View all related tutorials
Related Tags: c com image class list object diff components stack icons user sed entity icon order component ai define container show

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.