-1
任何人都可以解釋我們是如何得到下面的輸出在Applet類輸出 初始化... ... satrting停止...開始... ...停止啓動 我發現從以下鏈接 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);
}