可以解释我下面的一段代码

时间:2015-05-23 15:06:39

标签: java applet

任何人都可以解释我们如何在applet类输出中获得以下输出 初始化......坐着......停止......开始......停止......开始 我从以下链接找到了代码 https://docs.oracle.com/javase/tutorial/deployment/applet/lifeCycle.html

StringBuffer buffer;

public void init() {
    buffer = new StringBuffer();
    addItem("initializing... ");
}

public void start() {
    addItem("starting... ");
}

public void stop() {
    addItem("stopping... ");
}

public void destroy() {
    addItem("preparing for unloading...");
}

private void addItem(String newWord) {
    System.out.println(newWord);
    buffer.append(newWord);
    repaint();
}

public void paint(Graphics g) {
//Draw a Rectangle around the applet's display area.
    g.drawRect(0, 0, 
       getWidth() - 1,
       getHeight() - 1);

//Draw the current string inside the rectangle.
    g.drawString(buffer.toString(), 5, 15);
}

1 个答案:

答案 0 :(得分:5)

基本上,将根据applet的活动调用图像的开始和停止。只要“ 空闲 ”(通过最小化您的applet查看器屏幕),它就会停止()。然后,当它变为“ 活动 ”时(通过最大化您的applet查看器屏幕),它将再次启动():

enter image description here

来自此网站here

相关问题