Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to the main method for this class

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to the main method for this class

    Can somebody help me with the main method of this.


    import java.awt.*;
    import java.awt.geom.*;

    public class WobbleStroke implements Stroke {

    private float detail = 2;
    private float amplitude = 2;
    private static final float FLATNESS = 1;


    public WobbleStroke( float detail, float amplitude ) {
    this.detail = detail;
    this.amplitude = amplitude;
    }

    public Shape createStrokedShape( Shape shape ) {
    GeneralPath result = new GeneralPath();
    shape = new BasicStroke( 10 ).createStrokedShape( shape );
    PathIterator it = new FlatteningPathIterator( shape.getPathIterator( null ), FLATNESS );
    float points[] = new float[6];
    float moveX = 0, moveY = 0;
    float lastX = 0, lastY = 0;
    float thisX = 0, thisY = 0;
    int type = 0;
    boolean first = false;
    float next = 0;

    while ( !it.isDone() ) {
    type = it.currentSegment( points );
    switch( type ){
    case PathIterator.SEG_MOVETO:
    moveX = lastX = randomize( points[0] );
    moveY = lastY = randomize( points[1] );
    result.moveTo( moveX, moveY );
    first = true;
    next = 0;
    break;

    case PathIterator.SEG_CLOSE:
    points[0] = moveX;
    points[1] = moveY;
    // Fall into....

    case PathIterator.SEG_LINETO:
    thisX = randomize( points[0] );
    thisY = randomize( points[1] );
    float dx = thisX-lastX;
    float dy = thisY-lastY;
    float distance = (float)Math.sqrt( dx*dx + dy*dy );
    if ( distance >= next ) {
    float r = 1.0f/distance;
    float angle = (float)Math.atan2( dy, dx );
    while ( distance >= next ) {
    float x = lastX + next*dx*r;
    float y = lastY + next*dy*r;
    result.lineTo( randomize( x ), randomize( y ) );
    next += detail;
    }
    }
    next -= distance;
    first = false;
    lastX = thisX;
    lastY = thisY;
    break;
    }
    it.next();
    }

    return result;
    }

    private float randomize( float x ) {
    return x+(float)Math.random()*amplitude*2-1;
    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to the main method for this class

    help me with the main method
    Please explain what the main method is supposed to do. Be specific and give details.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Splitting up main method / class
    By Scren in forum What's Wrong With My Code?
    Replies: 53
    Last Post: February 8th, 2014, 04:54 PM
  2. Replies: 2
    Last Post: November 18th, 2012, 02:09 PM
  3. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  4. Main method/ class problem. I can't run any script!
    By BokBok in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2012, 05:14 PM
  5. Creating a scaleUp main method in a new class
    By Brainz in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 16th, 2010, 08:58 AM

Tags for this Thread