Changing Values in a Point

Point p1 = new Point(100, 100);
Point p2 = new Point(300, 100);
Point p3 = new Point(110, 100);
int x3 = 310;
Point p4 = new Point(100, 100);
static JFrame start = new JFrame("Start");

if(p3.x >= start.getWidth()-90)
{
    p3.x = (int) (p1.getX()+10);
    p3.setLocation(p3.x, p3.y);
    repaint();
}

if(key == KeyEvent.VK_S && !paused)
{
    p1.y++;
    p4.y++;
    p1.setLocation(p1.x, p1.y);
    test1.setBounds(new Rectangle(p1, new Dimension(64, 64)));
    repaint();
    sound.soundPlay(3);
}

In this, the x value of point p3 is supposed to be the same as the value of p1.getX()+10. The value is changed to 100+10, but I have changed 100 to a different value in the second block. How do I update p1 in the first block to match the p1 in the second block?

Answers


I have found the answer to my question. This is my new code:

Point p1 = new Point(100, 100);
Point p2 = new Point(300, 100);
Point p3 = new Point(110, 100);
Point p5 = new Point(310, 100);
Point p4 = new Point(90, 100);
static JFrame start = new JFrame("Start");

if(p3.x >= start.getWidth()-90)
{
    p3.x = start.getWidth()-70;
    p3.x = (int) (p1.getX()+10);
    p3.setLocation(p3.x, p3.y);
}

if(key == KeyEvent.VK_S && !paintingFBR && !paused)
{
    p1.y++;
    p3.y++;
    test1.setLocation(p1);
    test3.setLocation(p3);
}

Need Your Help

How would I convert List<Dictionary<string, object>> into a List<>

c# linq dictionary dynamic-properties

I have a design where class holds a List&lt;> of Summary objects, and each Summary is a dictionary of semi-dynamic properties. That is, every Summary in a given list will have the same keys in the

getting the positions of multiple images using javascript

javascript

What I want to achieve is when the user stops scrolling I want to position the closest image to the centre to the centre. This will, I think, involve me running a series of if statements to determine

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.