下面适合用appletviewer gainLookTime.java的方式!你最小化窗口!就认为你离开了当前窗口! import java.applet.*; import java.awt.*; import java.net.*; /* <applet code=gainLookTime width=300 height=300> </applet> */ public class gainLookTime extends Applet { TextField textField1 = new TextField(); long startTime,endTime,totalTime; //其实不一定需要这么多变量,就是为了清晰! public void init() { textField1.setColumns(10); textField1.setEditable(false); this.add(textField1, null); startTime=System.currentTimeMillis(); // Called once by the browser when it starts the applet } public void start() { // Called whenever the page containing this applet is made visible } public void stop() { endTime=System.currentTimeMillis(); totalTime=endTime-startTime; // Called whenever the page containing this applet is not visible } public void destroy() { // Called once when the browser destroys this applet } public void paint(Graphics g) { textField1.setText(Long.toString(totalTime/1000)+" seconds past"); // Called whenever this applet needs to repaint itself } }
import java.applet.*;
import java.awt.*;
import java.net.*;
/*
<applet code=gainLookTime width=300 height=300> </applet>
*/
public class gainLookTime extends Applet {
TextField textField1 = new TextField();
long startTime,endTime,totalTime;
//其实不一定需要这么多变量,就是为了清晰!
public void init() {
textField1.setColumns(10);
textField1.setEditable(false);
this.add(textField1, null);
startTime=System.currentTimeMillis(); // Called once by the browser when it starts the applet
}
public void start() {
// Called whenever the page containing this applet is made visible
}
public void stop() {
endTime=System.currentTimeMillis();
totalTime=endTime-startTime;
// Called whenever the page containing this applet is not visible
}
public void destroy() { // Called once when the browser destroys this applet
}
public void paint(Graphics g) {
textField1.setText(Long.toString(totalTime/1000)+" seconds past");
// Called whenever this applet needs to repaint itself
}
}