Results 1 to 6 of 6
  1. #1
    Drezir is offline Member
    Join Date
    Nov 2014
    Posts
    8
    Rep Power
    0

    Default adjustment of coordinates

    Hello,

    I have a problem. I need to draw graphs in swing. 1st i set starting point via Graphics.translate(). Then i need to set range for points on X and Y axis so for example all Panel.Width() would be in interval <-10,10> I do not know ho to do that. Would anyone help me please? Thank you very much

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: adjustment of coordinates

    Before anyone can help you, you'll need to try a little harder to give a proper problem description. Two short sentences is not going to cut it. What is this "Panel.Width()" you refer to for example?

    I have the idea you're just asking how to draw a line in a really difficult way.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: adjustment of coordinates

    Graphics.translate() does not set the starting point. It sets the origin. Some (x,y) coordinate, relative to the origin, is what dictates the starting point.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    Drezir is offline Member
    Join Date
    Nov 2014
    Posts
    8
    Rep Power
    0

    Default Re: adjustment of coordinates

    Quote Originally Posted by gimbal2 View Post
    Before anyone can help you, you'll need to try a little harder to give a proper problem description. Two short sentences is not going to cut it. What is this "Panel.Width()" you refer to for example?

    I have the idea you're just asking how to draw a line in a really difficult way.
    Sorry, it is JPanel.getWidth(). Problem is that if you draw graph on a paper then you choose your own scale (for example -2 , 2 for X axis). This thing i need to do in Swing. I need to tell JPanel that his left border should start from -2 except of 0 and his right border should be 2 except of JPanel.getWidth().

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: adjustment of coordinates

    If this isn't homework, you could use JFreeChart

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Drezir is offline Member
    Join Date
    Nov 2014
    Posts
    8
    Rep Power
    0

    Default Re: adjustment of coordinates

    Quote Originally Posted by DarrylBurke View Post
    If this isn't homework, you could use JFreeChart

    db
    I need to do it all alone. Here is an example where i am facing problem. Sinus line is extremlly zoomed out - i can see red sinus line on X axis.

    Java Code:
    private void functionSin(Graphics2D g){
            double previous=Math.sin(-width/2);
            g.setColor(Color.red);
            for (int i = -width/2; i < width/2; i++) {
                g.draw(new Line2D.Double(i,previous,i,previous=Math.sin(i)));
            }
        }
    // origin point is in the middle of JPanel
    // width = JPanel.getWidth()

Similar Threads

  1. Flipping these coordinates.
    By zFollette in forum New To Java
    Replies: 2
    Last Post: 01-15-2014, 01:41 AM
  2. Coordinates
    By Witik in forum New To Java
    Replies: 3
    Last Post: 09-06-2010, 07:05 AM
  3. coordinates and radius
    By tepong in forum New To Java
    Replies: 1
    Last Post: 08-21-2010, 06:38 PM
  4. JTextArea adjustment
    By Moncleared in forum AWT / Swing
    Replies: 3
    Last Post: 01-24-2009, 12:37 PM

Tags for this Thread

Posting Permissions

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