Java小程序应用程序-更新x绘制方法

Java小程序应用程序-更新x绘制方法,java,swing,applet,Java,Swing,Applet,我开始学习Java游戏开发,目前正在学习优秀的教程 这个游戏是基于Applet开发的 经过一些研究,我发现Applet是使用UIManager的重量级组件Swing 因此,当我阅读重新绘制文档时,它说: repaint(): Repaints this component. If this component is a lightweight component, this method causes a call to this component's <code>paint&l

我开始学习Java游戏开发,目前正在学习优秀的教程

这个游戏是基于Applet开发的

经过一些研究,我发现Applet是使用UIManager的重量级组件Swing

因此,当我阅读重新绘制文档时,它说:

repaint():

Repaints this component.
If this component is a lightweight component, this method
causes a call to this component's <code>paint</code>
method as soon as possible.  Otherwise, this method causes
a call to this component's <code>update</code> method as soon
as possible.
我知道repaint调用update,因为Applet是一个很重的组件,而不是paint

但是

在游戏教程中,作者/老师说:

。。。类似地,将始终使用run方法中的repaint语句调用绘制

这似乎确实正在发生。但为什么重新油漆叫做油漆呢

遵循为重要零件修剪的代码

谢谢

public class StartingClass extends Applet implements Runnable, {

private Robot robot;
private Image image, character;
private URL base;
private Graphics second;

@Override
public void init() {

    setSize(800, 480);
    setBackground(Color.BLACK);
    setFocusable(true);
    addKeyListener(this);
    Frame frame = (Frame) this.getParent().getParent();
    frame.setTitle("Q-Bot Alpha");

    base = getDocumentBase();
    character = getImage(base, "data/character.png");

}

@Override
public void start() {

    robot = new Robot();

    Thread thread = new Thread(this);
    thread.start();

}

@Override
public void stop() {

}

@Override
public void destroy() {

}

@Override
public void run() {

    while (true) {

        robot.update();

        repaint();

        try {
            Thread.sleep(17);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}

@Override

public void update(Graphics g) {

    if (image == null) {

        image = createImage(this.getWidth(), this.getHeight());         
        second = image.getGraphics();

    }

    second.setColor(getBackground());
    second.fillRect(0, 0, getWidth(), getHeight());
    second.setColor(getForeground());
    paint(second);

    g.drawImage(image, 0, 0, this);

}

@Override
public void paint(Graphics g) {     

    g.drawImage(character, robot.getCenterX() - 61, robot.getCenterY() - 63, this);

}

}

阅读:关于AWT和Swing图形的高级教程。但也要知道,像小程序这样的AWT使用的技术已经过时20年,而Swing只过时5-10年。好的。我的目标是学习游戏基本框架,然后进入Android。很抱歉,但我认为你不应该费心学习小程序游戏编程,因为我怀疑你学到的很多东西是否会传播到Android。我会关注Java和Android的基础知识,然后是Android游戏编程。我从这本开始,因为这是我在互联网上找到的最好的游戏教程。你知道安卓有什么好的吗?