⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typeword.java

📁 Java 多媒体技术(附源码) Java 3D API JavaSound API 各种格式的多媒体数据文件 JBuilder开发环境
💻 JAVA
字号:
package typeword;import java.awt.*;import java.awt.event.*;import java.applet.*;/** * <p>Title: 显示文字</p> * <p>Description: 以打字方式逐个循环显示文字</p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: 北京师范大学计算机系</p> * @author 孙一林 * @version 1.0 */public class TypeWord extends MultiThreadApplet {  boolean isStandalone = false;  String s_Word;                                             // 定义显示文字  int s_length;					                // 获取字符串长度  int x_character = 0;						// 显示到第几个字符  Font wordFont = new Font("宋体" , Font.BOLD , 50);  //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 TypeWord() {  }  //Initialize the applet  public void init() {    try {      s_Word = this.getParameter("param0", "你好,欢迎光临!");      s_length = s_Word.length();    }    catch(Exception e) {      e.printStackTrace();    }    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  //Component initialization  private void jbInit() throws Exception {  }  public void run() {    while(true) {      if( x_character++ >= s_length ){		// 显示字符计数加1        x_character = 0;				// 显示字符计数清0      }      repaint();							// 刷新显示      try{        Thread.sleep(300);				// 线程休眠      }      catch( InterruptedException e ) {      }    }  }  public void paint( Graphics g ) {			// 显示文字    g.setFont(wordFont);    g.setColor(Color.red);    g.drawString( s_Word.substring(0,x_character), 10, 50 );  }  //Get Applet information  public String getAppletInfo() {    return "Applet Information";  }  //Get parameter info  public String[][] getParameterInfo() {    String[][] pinfo =      {      {"param0", "String", ""},      };    return pinfo;  }  //Main method  public static void main(String[] args) {    TypeWord applet = new TypeWord();    applet.isStandalone = true;    Frame frame;    frame = new Frame() {      protected void processWindowEvent(WindowEvent e) {        super.processWindowEvent(e);        if (e.getID() == WindowEvent.WINDOW_CLOSING) {          System.exit(0);        }      }      public synchronized void setTitle(String title) {        super.setTitle(title);        enableEvents(AWTEvent.WINDOW_EVENT_MASK);      }    };    frame.setTitle("以打字方式逐个循环显示文字");    frame.add(applet, BorderLayout.CENTER);    applet.init();    applet.start();    frame.setSize(400,120);    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();    frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);    frame.setVisible(true);  }}

⌨️ 快捷键说明

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