重新绘制扩展JPanel的类时调用什么Methode?

时间:2019-05-30 19:58:37

标签: java jpanel repaint

我正在重画我的Obstacle,它从另一个Class以及Obstacle构造函数扩展了JPanel。在paintComponent(Graphics g)内部,从不打印Sys.out->从不调用方法。 我已经实现了所有这100次,并且找不到与其他工作代码之间的任何区别:c


    private Rectangle hitbox;
    private int x,y, width, height;
    public static final int BIG = 0, LARGE = 1, BIRD_LOW = 2, BIRD_MID = 3, BIRD_HIGH = 4;

    public Obstacle(int x, int y, int type) {
        this.x = x;
        this.y = y;

        [...]

        this.repaint();
    }

    public void updateMovement() {
        this.x -= 10;
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.BLACK);
        g2.draw(hitbox);
        System.out.println("Repainted");
    }
}

0 个答案:

没有答案