falconapplet.java~3~

来自「java基础,用JCreator Pro写一个界面更换的小程序,是北大清鸟s2的」· JAVA~3~ 代码 · 共 78 行

JAVA~3~
78
字号
package TestApplet;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.Date;

/******************************
 显示当前时间,每秒钟对显示作一次刷新
*******************************/

public class FalconApplet extends Applet implements Runnable{
    boolean isStandalone = false;
    BorderLayout borderLayout1 = new BorderLayout();

    Thread thread;

    //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 FalconApplet() {
    }

    //Initialize the applet
    public void init() {
        try {
            if(thread==null){
                thread=new Thread(this,"clock");
                thread.start();
            }
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //Component initialization
    private void jbInit() throws Exception {
    }

    //Get Applet information
    public String getAppletInfo() {
        return "Applet Information";
    }

    //Get parameter info
    public String[][] getParameterInfo() {
        return null;
    }

    public void run(){
        while(Thread.currentThread()==thread){
            repaint();
            try{
                thread.sleep(1000);
            }catch(Exception e){
                e.printStackTrace();
            }
       }
    }

    public void paint(Graphics g){
        int h,m,s;
        Date now=new Date();
        h=now.getHours();
        m=now.getMinutes();
        s=now.getSeconds();
        g.drawString(h+":"+m+":"+s,5,10);
    }
    public void stop(){
        thread=null;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?