I'm newbie in java, can you help me to this code.
the image needs to move diagonally

public void actionPerformed(ActionEvent e) {
        x += 3;
        if (x > 600) {
            y = random.nextInt(600);
            x = random.nextInt(-45);
            star.setX(x);
            star.setY(y);
        }

Recommended Answers

You're going to need to increment y and repaint() at some point.

Jump to Post

All 2 Replies

You're going to need to increment y and repaint() at some point.

the image needs to move diagonally

Does that imply a special way that the x and y values should change from one drawing of the image to the next drawing?
Should there be a relationship between the x,y for one position and the x,y for the next position? If so, what is the equation to compute a new x,y from an old x,y?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.