改变一点的价值观

时间:2012-09-08 02:03:58

标签: java swing awt 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);
}

在此,点p3的x值应该与p1.getX()+ 10的值相同。该值更改为100 + 10,但我在第二个块中将100更改为不同的值。如何更新第一个块中的p1以匹配第二个块中的p1?

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案。这是我的新代码:

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);
}