📄 watch.java~16~
字号:
package untitled1;import java.awt.*;import java.awt.event.*;import java.applet.*;import com.borland.jbcl.layout.*;public class watch extends java.applet.Applet implements Runnable{ int x = 0; Thread runner = null; boolean flag = false; boolean isStandalone = false; TextField text1 = new TextField(); Button button1 = new Button(); Button button2 = new Button(); XYLayout xYLayout1 = new XYLayout(); /**Get a parameter value*/ public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } /**Construct the applet*/ public watch() { } /**Initialize the applet*/ public void init() { flag = false; try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { text1.setFont(new java.awt.Font("Dialog", 0, 16)); text1.setText("0"); button1.setFont(new java.awt.Font("Dialog", 0, 16)); button1.setLabel("计时"); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button2.setFont(new java.awt.Font("Dialog", 0, 16)); button2.setLabel("清空"); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2_actionPerformed(e); } }); this.setLayout(xYLayout1); this.add(button2, new XYConstraints(200, 109, -1, -1)); this.add(button1, new XYConstraints(200, 60, -1, -1)); this.add(text1, new XYConstraints(68, 88, 82, -1)); } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } public void run(){ while(true){ int i,j; x += 1; i = (int)(x/60); text1.setText(String.valueOf(i)+":"+ String.valueOf(x-60*i)); try{ Thread.sleep(10); } catch(InterruptedException e){} } } public void start(){ if(flag){ if(runner==null){ runner=new Thread(this); runner.start(); } } } public void stop(){ if(runner!=null){ runner.stop(); runner=null; } } void button1_actionPerformed(ActionEvent e) { flag = !flag; if (flag) start(); else stop(); } void button2_actionPerformed(ActionEvent e) { text1.setText("0"); x = 0; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -