绘制函数的迭代次数不会超过Java的3倍

时间:2016-01-05 23:15:47

标签: java swing

所以每次我运行程序并输入1进入系统时,它只允许我移动椭圆一次,然后程序将打印调试2次而不移动椭圆。为什么呢?

    import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Scanner;
import javax.swing.JFrame;

/**
 *
 * @author Admin
 */
public class TestingGame extends JFrame{
    public Scanner scan = new Scanner(System.in);
    public static int x = 0;
    public static int y = 0;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        TestingGame myFrame = new TestingGame();
        myFrame.setSize(1000,1000);
        myFrame.setLocationRelativeTo(null);
        myFrame.setDefaultCloseOperation(myFrame.EXIT_ON_CLOSE);
        myFrame.setVisible(true);


    }
    public void paint(Graphics g){
        update(g);
    }    
    public void update(Graphics g){
        Graphics2D ga = (Graphics2D)g;
        ga.drawOval(x, y, 50, 50);
        int input = scan.nextInt();
        if(input == 1){
            System.out.println("Debug");
            x = x + 100;
            y = y + 100;
        }
    }


}

0 个答案:

没有答案