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 15 of 15

Thread: problem with coordinates (GUI)

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default problem with coordinates (GUI)

    Hi everybody
    i have written a java code (GUI) , which a red marker (red point) should follow a line between 2 positions, the program works good but the red point is not exact on the line (it just moves one t edge of the line). now i need some help to change x and y coordinate to be one the line not on the edge..
    thanks

    import java.util.LinkedList;
    import java.util.ListIterator;
    import javax.swing.*;
    import java.awt.*;

    public class JavaGrafikPanel1 extends JPanel
    {
    public boolean animation;
    public animcircle mc;
    JavaGrafikPanel1()
    {
    Color mycolor = new Color(10,50,100);
    setBackground(mycolor);
    this.animation = false;
    mc = new animcircle();
    mc.firstPoint = new Position(0, 0);
    mc.lastPoint = new Position(0, 0);
    }
    private LinkedList points;
    public LinkedList getPoints()
    {
    return points;
    }
    public void setPoints(LinkedList points)
    {
    this.points = points;
    }
    protected void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    ListIterator li = points.listIterator();
    Position p = new Position(0, 0);
    Position q = new Position(0, 0);
    while(li.hasNext())
    {
    p = (Position)li.next();
    g.setColor(Color.pink);
    g.drawOval((int)p.getX(), (int)p.getY(),3,3);
    if(li.hasNext())
    {
    q = (Position)li.next();
    g.setColor(Color.white);
    g.drawLine((int)p.getX(), (int)p.getY(), (int)q.getX(), (int)q.getY());
    li.previous();
    }
    else
    break;
    }
    if(this.animation)
    {
    Position cr = new Position(0,0);
    int index = 0;
    if((cr = mc.getNextPosition()) == null)
    {
    index = points.indexOf(mc.lastPoint);
    mc.firstPoint = mc.lastPoint;
    if(points.size() > index+1)
    mc.lastPoint = (Position)points.get(index+1);
    else // stop animation
    {
    animation = false;
    return;
    }
    mc.step = 0;
    if((cr = mc.getNextPosition()) == null)
    {
    animation = false;
    return;
    }
    }
    g.drawOval(((int)cr.getX())/2,((int)cr.getY())/2,8,8);
    g.setColor(Color.red);
    g.fillOval(((int)cr.getX())/2,((int)cr.getY())/2,8,8);
    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: problem with coordinates (GUI)

    How can the posted code be compiled and executed for testing? I don't see a main() method or a frame.

    Please edit your post and wrap your code with
    [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.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem with coordinates (GUI)

    [AnimPos]
    import java.util.LinkedList;
    import java.util.ListIterator;
    import javax.swing.*;
    import java.awt.event.*;


    public class AnimPos extends JFrame
    {
    private JavaGrafikPanel1 jpnl;
    public static void main(String args[]) throws Exception
    {
    AnimPos p = new AnimPos();

    p.jpnl = new JavaGrafikPanel1();
    p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    p.setContentPane(p.jpnl);
    p.setSize(400,300);
    p.setVisible(true);
    LinkedList pos = new LinkedList();
    p.jpnl.setPoints(pos);
    pos = p.loadPoints();
    double dist = 0;
    ListIterator itr = pos.listIterator(0);
    Position fpoint;
    Position lpoint;
    if(itr.hasNext())
    {
    fpoint = (Position)itr.next();
    itr.previous();
    }
    while(itr.hasNext())
    {
    lpoint = (Position)itr.next();
    fpoint = lpoint;
    dist += fpoint.distance(lpoint);
    }
    System.out.print(dist);
    }
    public AnimPos()
    {
    ActionListener timerListener = new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    if(jpnl.animation)
    {
    jpnl.repaint();
    }
    else
    {
    }
    }
    };
    Timer t = new Timer(100, timerListener);
    t.start();
    }

    public LinkedList loadPoints() throws Exception
    {
    java.io.BufferedReader in_reader = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
    System.out.println("How many positions?: \n");
    String str = in_reader.readLine();
    int antal = Integer.parseInt(str);
    System.out.println("Write positions in each line seperated by comma. Ex. \nX1,Y1\nX2,Y2\n");
    String[] doubles;
    LinkedList poser = new LinkedList();
    for(int i=0;i<antal;i++)
    {
    str= in_reader.readLine();
    doubles = str.split(",");
    double a = Double.parseDouble(doubles[0]);
    double b = Double.parseDouble(doubles[1]);
    poser.add(new Position(a, b));
    this.jpnl.setPoints(poser);
    this.repaint();
    }
    System.out.println("\nShow Animation?(Y/N)\n");
    this.jpnl.mc.firstPoint = new Position(0,0);
    this.jpnl.mc.lastPoint = (Position)poser.getFirst();
    str = in_reader.readLine();
    if(str.equals("Y") || str.equals("y"))
    {
    this.moveIt();
    }
    return poser;
    }
    public void moveIt()
    {
    this.jpnl.animation = true;
    }
    }[/AnimPos]
    [JavaGrafikPanel1 ]
    import java.util.LinkedList;
    import java.util.ListIterator;
    import javax.swing.*;
    import java.awt.*;

    public class JavaGrafikPanel1 extends JPanel
    {
    public boolean animation;
    public animcircle mc;
    JavaGrafikPanel1()
    {
    Color mycolor = new Color(10,50,100);
    setBackground(mycolor);
    this.animation = false;
    mc = new animcircle();
    mc.firstPoint = new Position(0, 0);
    mc.lastPoint = new Position(0, 0);
    }
    private LinkedList points;
    public LinkedList getPoints()
    {
    return points;
    }
    public void setPoints(LinkedList points)
    {
    this.points = points;
    }
    protected void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    ListIterator li = points.listIterator();
    Position p = new Position(0, 0);
    Position q = new Position(0, 0);
    while(li.hasNext())
    {
    p = (Position)li.next();
    g.setColor(Color.pink);
    g.drawOval((int)p.getX(), (int)p.getY(),3,3);
    if(li.hasNext())
    {
    q = (Position)li.next();
    g.setColor(Color.white);
    g.drawLine((int)p.getX(), (int)p.getY(), (int)q.getX(), (int)q.getY());
    li.previous();
    }
    else
    break;
    }
    if(this.animation)
    {
    Position cr = new Position(0,0);
    int index = 0;
    if((cr = mc.getNextPosition()) == null)
    {
    index = points.indexOf(mc.lastPoint);
    mc.firstPoint = mc.lastPoint;
    if(points.size() > index+1)
    mc.lastPoint = (Position)points.get(index+1);
    else // stop animation
    {
    animation = false;
    return;
    }
    mc.step = 0;
    if((cr = mc.getNextPosition()) == null)
    {
    animation = false;
    return;
    }
    }
    g.drawOval(((int)cr.getX())/2,((int)cr.getY())/2,8,8);
    g.setColor(Color.red);
    g.fillOval(((int)cr.getX())/2,((int)cr.getY())/2,8,8);
    }
    }
    }
    [/JavaGrafikPanel1 ]

    ------------------------------
    [Position]

    public class Position
    {
    public Position(double x, double y)
    {
    this.X = x;
    this.Y = y;
    }
    private double X;
    private double Y;
    public String toString()
    {
    return "(" + Double.toString(X) + "," + Double.toString(Y) + ")";
    }
    public void SetPosition(double x,double y)
    {
    this.X = x;
    this.Y = y;
    }
    public double getX()
    {
    return this.X;
    }
    public double getY()
    {
    return this.Y;
    }
    public double distance(Position q)
    {
    return java.lang.Math.sqrt(java.lang.Math.pow(this.X - q.getX(),2) + java.lang.Math.pow(this.Y - q.getY(),2));
    }
    public double direction(Position q)
    {
    return (this.Y - q.getY())/(this.X - q.getX()) ;
    }
    }
    [/Position]

    -----------------------------
    [animcircle]
    public class animcircle
    {

    public Position firstPoint;
    public Position lastPoint;
    public int step;
    public int pixeljumper;
    public animcircle()
    {
    this.firstPoint = new Position(0, 0);
    this.lastPoint = new Position(0, 0);
    this.step = 0; //in order to begin from 0 at the main program;
    pixeljumper = 1;
    }

    public Position getNextPosition()
    {
    step++;
    Position p = new Position(0, 0);
    double m = this.firstPoint.direction(lastPoint);
    double y = 0;
    double x = 0;
    if(firstPoint.getX() - lastPoint.getX() == 0)
    {
    if(firstPoint.getY() - lastPoint.getY() == 0)
    {

    return null;
    }

    int totstep = (int)(firstPoint.getY() - lastPoint.getY())/pixeljumper + 1;

    if(step< Math.abs(totstep))
    {
    if(firstPoint.getY() > lastPoint.getY())
    y = firstPoint.getY() - (step-1)*pixeljumper;
    else
    y = firstPoint.getY() + (step-1)*pixeljumper;
    x = (y-firstPoint.getY())/m +firstPoint.getX();
    p.SetPosition(x, y);
    }
    else
    {
    return null;
    }
    }
    else
    {

    int totstep = (int)(firstPoint.getX() - lastPoint.getX())/pixeljumper + 1;

    if(step< Math.abs(totstep))
    {
    if(firstPoint.getX() > lastPoint.getX())
    x = firstPoint.getX() - (step-1)*pixeljumper;
    else
    x = firstPoint.getX() + (step-1)*pixeljumper;
    y = (x-firstPoint.getX())*m +firstPoint.getY();
    p.SetPosition(x, y);
    }
    else
    {
    return null;
    }

    }
    return p;
    }
    }
    [/animcircle]

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: problem with coordinates (GUI)

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Can you copy the full contents of the console and paste it here showing what was entered when the program was executed so the code can be tested with the same input that you used.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default coordinates (GUI)

    Hi
    i have written a java code (GUI) , which a red marker (red point) should follow a line between 2 positions, the program works good but the red point is not exact on the line (it just moves one t edge of the line). now i need some help to change x and y coordinate to be one the line not on the edge..
    thanks
    Here is all the classes and code
    import java.util.LinkedList;
    import java.util.ListIterator;
    import javax.swing.*;
    import java.awt.event.*;
     
     
    public class AnimPos extends JFrame
    {
            private JavaGrafikPanel1 jpnl;
    	public static void main(String args[]) throws Exception
            {
                AnimPos p = new AnimPos();
     
                p.jpnl = new JavaGrafikPanel1();
                p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                p.setContentPane(p.jpnl);
                p.setSize(400,300);
                p.setVisible(true);
                LinkedList pos = new LinkedList();
                p.jpnl.setPoints(pos);
                pos = p.loadPoints();            
                double dist = 0;
                ListIterator itr = pos.listIterator(0);
                Position fpoint;
                Position lpoint;
                if(itr.hasNext())
                    {
                        fpoint = (Position)itr.next();
                        itr.previous();
                    }
                while(itr.hasNext())
                {
                    lpoint = (Position)itr.next();
                    fpoint = lpoint;
                    dist += fpoint.distance(lpoint);
                }
                System.out.print(dist);
    	}
            public AnimPos()
            {
                ActionListener timerListener = new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        if(jpnl.animation)
                        {
                            jpnl.repaint();
                        }
                        else
                        {
                        }
                    }
                };
                Timer t = new Timer(100, timerListener);
                t.start();
            }
     
            public LinkedList loadPoints() throws Exception
            {
                java.io.BufferedReader in_reader = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
                System.out.println("How many positions?: \n");
                String str = in_reader.readLine();
                int antal = Integer.parseInt(str);
                System.out.println("Write positions in each line seperated by comma. Ex. \nX1,Y1\nX2,Y2\n");
                String[] doubles;
                LinkedList poser = new LinkedList();
                for(int i=0;i<antal;i++)
                {
                        str= in_reader.readLine(); 
                        doubles = str.split(",");
                        double a = Double.parseDouble(doubles[0]);
                        double b = Double.parseDouble(doubles[1]);
                        poser.add(new Position(a, b));
                        this.jpnl.setPoints(poser);
                        this.repaint();
                }
                System.out.println("\nShow Animation?(Y/N)\n");
                this.jpnl.mc.firstPoint = new Position(0,0);
                this.jpnl.mc.lastPoint = (Position)poser.getFirst();
                str = in_reader.readLine();
                if(str.equals("Y") || str.equals("y"))
                {
                    this.moveIt();
                }
                return poser;
            }
            public void moveIt()
            {
                this.jpnl.animation = true;
            }
    }

    import java.util.LinkedList;
    import java.util.ListIterator;
    import javax.swing.*;
    import java.awt.*;
     
    public class JavaGrafikPanel1 extends JPanel
    {
        public boolean animation;
        public animcircle mc;
        JavaGrafikPanel1()
        {
            Color mycolor = new Color(10,50,100);
            setBackground(mycolor);
            this.animation = false;
            mc = new animcircle();
            mc.firstPoint = new Position(0, 0);
            mc.lastPoint = new Position(0, 0);
        }
        private LinkedList points;
        public LinkedList getPoints()
        {
            return points;
        }
        public void setPoints(LinkedList points)
        {
            this.points = points;
        }
        protected void paintComponent(Graphics g)
        {
    	super.paintComponent(g);
            ListIterator li = points.listIterator();
            Position p = new Position(0, 0);
            Position q = new Position(0, 0);
            while(li.hasNext())
            {
                p = (Position)li.next();
                g.setColor(Color.pink);
                g.drawOval((int)p.getX(), (int)p.getY(),3,3);
                if(li.hasNext())
                {
                    q = (Position)li.next();
                    g.setColor(Color.white);
                    g.drawLine((int)p.getX(), (int)p.getY(), (int)q.getX(), (int)q.getY());
                    li.previous();
                }
                else
                    break;
            }
            if(this.animation)
            {
                Position cr = new Position(0,0);
                int index = 0;
                if((cr = mc.getNextPosition()) == null)
                {
                    index = points.indexOf(mc.lastPoint);
                    mc.firstPoint = mc.lastPoint;
                    if(points.size() > index+1)
                        mc.lastPoint = (Position)points.get(index+1);
                    else    // stop animation
                    {
                        animation = false;
                        return;
                    }
                    mc.step = 0;
                    if((cr = mc.getNextPosition()) == null)
                    {
                        animation = false;
                        return;                    
                    }
                }
                g.drawOval(((int)cr.getX())/2,((int)cr.getY())/2,8,8);
                g.setColor(Color.red);
                g.fillOval(((int)cr.getX())/2,((int)cr.getY())/2,8,8);
            }
        }
    }

     
    public class Position
    {
           public Position(double x, double y)
            {
                this.X = x;
                this.Y = y;
            }
            private double X;
            private double Y;
            public String toString()
            {
                return "(" + Double.toString(X) + "," + Double.toString(Y) + ")";
            }
            public void SetPosition(double x,double y)
            {
                this.X = x;
                this.Y = y;
            }
            public double getX()
            {
                return this.X;
            }
            public double getY()
            {
                return this.Y;
            }
            public double distance(Position q)
            {
                return java.lang.Math.sqrt(java.lang.Math.pow(this.X - q.getX(),2) + java.lang.Math.pow(this.Y - q.getY(),2));
            }
            public double direction(Position q)
            {
                return (this.Y - q.getY())/(this.X - q.getX())  ;
            }
    }
    public class animcircle
    {
     
        public Position firstPoint;
        public Position lastPoint;
        public int step;
        public int pixeljumper;
        public animcircle()
        {
            this.firstPoint = new Position(0, 0);
            this.lastPoint = new Position(0, 0);
            this.step = 0; //in order to begin from 0 at the main program;
            pixeljumper = 1;
        }
     
        public Position getNextPosition()
        {
            step++;
            Position p = new Position(0, 0);
            double m = this.firstPoint.direction(lastPoint);
            double y = 0;
            double x = 0;
            if(firstPoint.getX() - lastPoint.getX() == 0)
            {
                if(firstPoint.getY() - lastPoint.getY() == 0)
                {
     
                    return null;
                }
     
                int totstep = (int)(firstPoint.getY() - lastPoint.getY())/pixeljumper + 1;
     
                if(step< Math.abs(totstep))
                {
                    if(firstPoint.getY() > lastPoint.getY())
                        y = firstPoint.getY() - (step-1)*pixeljumper;
                    else
                        y = firstPoint.getY() + (step-1)*pixeljumper;
                    x = (y-firstPoint.getY())/m +firstPoint.getX();
                    p.SetPosition(x, y);
                }
                else
                {
                    return null;
                }
            }
            else
            {
     
                int totstep = (int)(firstPoint.getX() - lastPoint.getX())/pixeljumper + 1;
     
                if(step< Math.abs(totstep))
                {
                    if(firstPoint.getX() > lastPoint.getX())
                        x = firstPoint.getX() - (step-1)*pixeljumper;
                    else
                        x = firstPoint.getX() + (step-1)*pixeljumper;
                    y = (x-firstPoint.getX())*m +firstPoint.getY();                
                    p.SetPosition(x, y);
                }
                else
                {
                    return null;
                }
     
            }
            return p;
        }
    }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: problem with coordinates (GUI)

    I've merged the duplicate threads.

    Can you copy the full contents of the console and paste it here showing what was entered when the program was executed so the code can be tested with the same input that you used.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem with coordinates (GUI)

    Hi Norm,
    thanks for reply,
    there is no problem to execute the code, my question is when i run the code, in the animation part, should a red marker follow the line between to positions, but the red point is one edge of line not exact on the line, now i want it to be on line when it moves on line!!! hope that i clear with my explanation!
    thanks

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: problem with coordinates (GUI)

    When the code is executed it wants input. What is entered?
    Can you copy the full contents of the console and paste it here showing what was entered when the program was executed so the code can be tested with the same input that you used.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem with coordinates (GUI)

    here is the input:
    How many positions?:

    5
    Write positions in each line seperated by comma. Ex.
    X1,Y1
    X2,Y2

    10,40
    40,60
    90,110
    150,200
    10,60

    Show Animation?(Y/N)

    y
    0.0

    this JavaGrafikPanel1 is correct code not the last one is posted
    import java.util.LinkedList;
    import java.util.ListIterator;
    import javax.swing.*;
    import java.awt.*;
     
    public class JavaGrafikPanel1 extends JPanel
    {
        public boolean animation;
        public animcircle mc;
        JavaGrafikPanel1()
        {
            Color mycolor = new Color(10,50,100);
            setBackground(mycolor);
            this.animation = false;
            mc = new animcircle();
            mc.firstPoint = new Position(0, 0);
            mc.lastPoint = new Position(0, 0);
        }
        private LinkedList points;
        public LinkedList getPoints()
        {
            return points;
        }
        public void setPoints(LinkedList points)
        {
            this.points = points;
        }
        protected void paintComponent(Graphics g)
        {
    	super.paintComponent(g);
            ListIterator li = points.listIterator();
            Position p = new Position(0, 0);
            Position q = new Position(0, 0);
            while(li.hasNext())
            {
                p = (Position)li.next();
                g.setColor(Color.pink);
                g.drawOval((int)p.getX(), (int)p.getY(),3,3);
                if(li.hasNext())
                {
                    q = (Position)li.next();
                    g.setColor(Color.white);
                    g.drawLine((int)p.getX(), (int)p.getY(), (int)q.getX(), (int)q.getY());
                    li.previous();
                }
                else
                    break;
            }
            if(this.animation)
            {
                Position cr = new Position(0,0);
                int index = 0;
                if((cr = mc.getNextPosition()) == null)
                {
                    index = points.indexOf(mc.lastPoint);
                    mc.firstPoint = mc.lastPoint;
                    if(points.size() > index+1)
                        mc.lastPoint = (Position)points.get(index+1);
                    else    // stop animation
                    {
                        animation = false;
                        return;
                    }
                    mc.step = 0;
                    if((cr = mc.getNextPosition()) == null)
                    {
                        animation = false;
                        return;                    
                    }
                }
                g.drawOval((int)cr.getX(),(int)cr.getY(),8,8);
                g.setColor(Color.red);
                g.fillOval((int)cr.getX(),(int)cr.getY(),8,8);
            }
        }
    }

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: problem with coordinates (GUI)

    A suggested change to make testing easier and faster. Put the answers in the program:
       StringReader sr = new StringReader("5\n10,40\n40,60\n90,110\n150,200\n10,60\nY\n");
        java.io.BufferedReader in_reader = new java.io.BufferedReader(sr); //new java.io.InputStreamReader(System.in));

    What is wrong with the code now? The red ball stays centered on the line with the code in post#9
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem with coordinates (GUI)

    yes , the problem is the red ball moves on the edge of line and doesnt stay centered, for example try these new inputs, between 2 first point it is on the center of the line , but after that between the other positions , it goes on one side of the line, if u try this new input u will see what i mean, thank alot for helping
    How many positions?:

    4
    Write positions in each line seperated by comma. Ex.
    X1,Y1
    X2,Y2

    20,50
    90,150
    250,70
    30,50

    Show Animation?(Y/N)

    y
    0.0

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: problem with coordinates (GUI)

    In the future when posting input for the program, use the StringReader constructor I posted in #10.
    That makes for easier testing, instead of having to type in all those numbers at the console.

    --- Update ---

    What is different between the lines in post#9 and post#11?
    The ball stayed centered for post#9 and was below the second line in post#11.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem with coordinates (GUI)

    that's the point, in post #9 stayed centered, but when i try for post #11 it doesnt work good. same code and no changes , but different input works insane.
    can u do me a favor and tell me why is it so?
    StringReader sr = new StringReader("4\n20,50\n90,150\n250,70\n30,50\nY\n");
    java.io.BufferedReader in_reader = new java.io.BufferedReader(sr); //new java.io.InputStreamReader(System.in));

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: problem with coordinates (GUI)

    The x,y used for the draw and fill are on the line and not properly offset to center the ball on the line.
    Look at the definition of where the x,y location is for the draw and fill methods. Take a piece of paper and draw the line and a centered ball. Look at where the x,y location must be for the ball to be centered on the line.

    The code has no comments describing its logic and requires too much time to figure out what the code is doing or what the purpose of any class or method is.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem with coordinates (GUI)

    i will try, thanks anyway

Similar Threads

  1. Java Coordinates
    By qspec in forum Java Theory & Questions
    Replies: 1
    Last Post: September 13th, 2012, 10:15 PM
  2. Help with plotting x-y coordinates.
    By mixmagz in forum Object Oriented Programming
    Replies: 5
    Last Post: January 23rd, 2012, 08:41 AM
  3. Mapping real coordinates into GUI
    By gloor in forum AWT / Java Swing
    Replies: 2
    Last Post: May 26th, 2011, 08:35 AM
  4. Retrieve coordinates of other windows
    By Knox in forum AWT / Java Swing
    Replies: 1
    Last Post: April 10th, 2011, 02:03 PM
  5. GUI Problem
    By bulldog in forum AWT / Java Swing
    Replies: 1
    Last Post: December 11th, 2009, 12:47 PM