Results 1 to 4 of 4
  1. #1
    Manojx is offline Member
    Join Date
    Mar 2011
    Posts
    12
    Rep Power
    0

    Question How to provide x & y values for polygon ? Plz refer below

    :confused:

    hi to all

    Here i have been trying to do a paint application something like there are
    2 buttons such as RECTANGLE , ELLIPSE by following those buttons you have some
    EMPTY SPACE which enables you to draw these shapes mentioned Above

    based on your need you can select a shape either one of these before you draw
    so that selected image will be drawn in the EMPTY SPACE but the image appears only after your mouse pointer drawn on the empty space, but not image appeared automatically when the button is selected

    So to implement this RECTANGLE ,ELLIPSE i just want these two methods

    drawRect(x,y,w,h)

    Ellipse2D.Float(x,y,w,h)

    for EXAMPLE Consider about RECTANGLE in this methods to find height & width of RECTANGLE i just create 2 variable and by subtracting end point of cursor with the Starting point found height and width of rectangle
    this is inside a public void paint method

    int width = end.x - start.x; // declaring variables
    int height = end.y - start.y; // declaring variables

    g.drawRect(start.x, start.y, width, height); // declaring variables to draw RECTANGLE

    but now i want to implement POLYGON and the method of this something like
    this X & Y points with the N Points

    int xpoints[] = {25, 145, 25, 145, 25};
    int ypoints[] = {25, 25, 145, 145, 25};
    int npoints = 5;

    g.drawPolygon(xpoints, ypoints, npoints);

    so in this case i exactly don't know How to provide X & Y values based on where the polygon drawn in empty space

    and i'm not allowed to draw polygon just by providing X & Y Values(NUMBERS)

    Instead of that i need something like getting X & Y values from a EMPTY SPACE and apply those X & Y values instead of numbers

    DO I need to use something like X1.y1.x2,y2,x3,y3........x5,y5

    i tried for this but not working any help would be much appreciated

    Thanks in advance
    Mano

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    i tried for this but not working

    What did you try?

    The method you give the user for entering the coordinates of the polygon should be consistent with whatever method they use for entering the rectangle. So, for example, if the rectangle is entered with left mouse clicks, you might do the same for the polygon vertices adding a double click to signal the last vertex of the polygon.

    In terms of how you accumulate the vertices before you create the poly gon, don't use variables xN, yN, etc because you have no idea how many you will need. Instead use a list - or, if you haven't come across lists, you might try an array. Lists take time to learn about, but you may find them a more natural solution than arrays.

  3. #3
    Manojx is offline Member
    Join Date
    Mar 2011
    Posts
    12
    Rep Power
    0

    Question

    thnx for being replied anyhow i got the idea of yours but how do i implement the double click to signal for the vertex of polygon

    i don't have any idea can you give me an example for implementing double click to polygon vertex

    in additon of that have you got any reference sites to create color panel something like whenever a color is chosen from a list panel so as based on the color selected, that color is to be filled inside shapes

    and the same thing has to be done to color lines of shapes
    thanks

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    how do i implement the double click to signal for the vertex of polygon

    There's a full example in Oracle's Tutorial on the page How to Write a Mouse Listener.

    have you got any reference sites to create color panel

    See How to Use Color Choosers.

    The Swing section of the Tutorial has plenty of discussion and examples.
    Last edited by pbrockway2; 03-15-2011 at 06:55 PM.

Similar Threads

  1. Refer to an object from an array/for loop
    By Chro in forum New To Java
    Replies: 2
    Last Post: 11-09-2010, 06:12 PM
  2. how provide the method ?
    By pruton in forum New To Java
    Replies: 4
    Last Post: 06-13-2010, 04:41 PM
  3. Please provide some help
    By saurabh_87 in forum New To Java
    Replies: 3
    Last Post: 04-23-2009, 08:38 AM
  4. can anybody please provide me the java tutorials
    By vislawath.jawaharlal in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-07-2009, 03:08 PM
  5. Refer a good Java compiler
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •