Results 1 to 8 of 8

Thread: Coordinate System?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Coordinate System?

    I wanted to see if i could get some ideas on what would be the best way to create a floating coordinate system using two JSliders and a Canvas. Ive been having trouble figuring out how to sync up the JSliders and the drawing of the lines on the Canvas.

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Design Pattern Question

    ? I am a big confused here ? Doesn't the JSlider have an event? Can't you just use it?



    - ØØ -

  3. #3
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Design Pattern Question

    Hey, this is exaclty what I'm doing. I did something with an interest rate:

    int value = interestRateSlider.getValue();
    int rate = (double)(1+(.01*value));


    First of all, I made my slider go from like 0 to 500 so that I would have plenty of room for decimals and stuff like that.
    I got the value from the slider, then created a double out of it with 2 decimal places, and that was it. After that, mortgages were calculated and points were added to arraylists and then it was off to the canvas class to repaint.

  4. #4

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Design Pattern Question

    Posted by NoteMe

    ? I am a big confused here ? Doesn't the JSlider have an event? Can't you just use it?
    What i want to do is have a JSlider at the south portion of a JFrame and a JSlider to the east each with a line comming out spanning across a Canvas. So the lines are always going to be intersecting.

    I guess what i need is two classes that extend JSlider and implement a ChangeListener interface and ask for a repaint when a ChangeEvent is fired off. The problem is that JSlider has a getValue() method and to draw a line i need to use g.drawLine(int x1, int y1, int x2, int y2). Also if the drawLine() method is shared by both JSlider classes how does the paint method within my class that extends canvas know which JSlider is being slid?

  5. #5
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Coordinate System?

    You need to have variables or flags in the other class. I did the same thing except I drew intersecting lines with the mouse motion listener.

    public void changeHappend(ChangeEvent ce)
    {
    int x = ce.getValue();
    CanvasName.x = x;
    CanvasName.repaint();
    }


    in canvas class:


    if (x != 0 && y != 0)
    {
    g.drawLine(0,y,100,y);
    g.drawLine(x,0,x,100);
    }

  6. #6

  7. #7
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Coordinate System?

    Ever figure something out?

  8. #8

Posting Permissions

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



Click Here to Expand Forum to Full Width