-2
그래서 클래스를 만들려고하는 프로그램이있어서 농장과 태양이있는 국가 장면을 만들어야합니다. 태양은 위아래로 튀어 나와야합니다. 내가 직면하고있는 현재의 문제는 태양이 계속 내려 가고, 튀어 오르지 않을 것이라는 것입니다. 여기 내 코드는 다음과 같습니다.Dr.Java를 사용하여 바운스하는 방법을 알고 싶습니다.
import javax.swing.*;
import java.awt.*;
/**
* Date: Oct 14, 2016
* Author:
* Description: Shows a country side with a farm and a sun bouncing up and down.
*/
public class WeAreInThePictures extends JFrame
{
ImageIcon sun, farm, bG; //assigns sun, farm and background to an image variable
static int x = 0, y = -50; //starting position of the sun
static int ySpeed = 10; //speed in y direction
static double delay = 1.0;
public WeAreInThePictures() {
super ("We Are In The Pictures!");
setSize (852, 480);
bG = new ImageIcon ("1.jpg");
sun = new ImageIcon ("sun.png");
farm = new ImageIcon ("farm.png");
setVisible (true);
}
public static void main(String[] args) {
new WeAreInThePictures();
}
public void paint (Graphics g)
{
for (int i = 0; i < 1000; i++)
{
bG.paintIcon (this, g, 0, 0);
farm.paintIcon (this, g, 500, 50);
y = y + ySpeed;
if (ySpeed > 0)
{
sun.paintIcon (this, g, x, y);
for (int j = 0; j < 550000; j++)
{
delay = Math.pow (delay, 1);
}
}
else if (y > 50)
{
ySpeed = ySpeed - 1;
}
else if (y <= 0)
{
ySpeed = ySpeed - 1;
}
}
}
}
누군가가 나에게 무엇이 잘못 되었습니까, 어떻게 수정해야하며 왜 문제가 발생하는지 설명 할 수 있습니까?