设为首页 加入收藏

TOP

Java实现打字机效果源代码
2014-11-24 02:58:06 来源: 作者: 【 】 浏览:1
Tags:Java 实现 打字机 效果 源代码

  import java.applet.*;


  import java.awt.*;


  import java.io.*;


  import java.net.URL;


  import java.util.*;


  public class Typewriter4 extends Applet implements Runnable


  {


  AudioClip hit, cr, ding ;


  boolean alreadyRun = false,


  soundOn = false,


  loop = false;


  Color bgColor = Color.lightGray,


  textColor = Color.black ;


  Font font ;


  Image offScreen, background ;


  int width, height,


  currentline = 0,


  currentword = 0,


  currentletter = 0,


  depth = 0,


  margin = 0,


  cycles = 0,


  step = 0,


  pause = 0,


  speed = 0,


  update = 0,


  linecount = 0 ;


  long lastread = 0;


  MediaTracker mt ;


  String soundactivation, text, textfile, target ;


  Thread woohoo = null;


  URL hotlink = null;


  Vector lines = null;


  public Typewriter4()


  {


  alreadyRun = false;


  soundOn = false;


  loop = true;


  soundactivation = "enter";


  }


  public void buildLines()


  {


  lines = new Vector();


  FontMetrics fontmetrics =


  offScreen.getGraphics().getFontMetrics();


  StringTokenizer strTok = new StringTokenizer(text, "\n") ;


  while (strTok.hasMoreTokens())


  {


  StringTokenizer strTok1 =


  new StringTokenizer(strTok.nextToken());


  int wordcount = strTok1.countTokens();


  String[] words = new String[wordcount];


  for(int i = 0; i < wordcount; i++)


  words[i] = strTok1.nextToken();


  String s = "" ;


  for(int j = 0; j < wordcount; j++)


  {


  s = s != null s + words[j] + " " : words[0];


  if(fontmetrics.stringWidth(s) > width - margin * 2)


  {


  lines.addElement(s.substring(0,


  s.lastIndexOf(" ", s.lastIndexOf(" ") - 1)));


  s = words[j] + " ";


  }


  }


  lines.addElement(s);


  linecount = lines.size();


  }


  depth = height - fontmetrics.getHeight() / 2;


  }


  public void checkTextfile()


  {


  loop = true;


  text = "";


  try


  {


  DataInputStream datainputstream = new


  DataInputStream((new URL(getDocumentBase(),


  textfile)).openStream());


  boolean flag = true;


  while(flag)


  {


  String s = datainputstream.readLine();


  if(s == null)


  flag = false;


  else


  text = text + s + "\n";


  }


  datainputstream.close();


  lastread =


  (new Long((new Date()).getTime())).longValue();


  return;


  }


  catch(Exception exception)


  {


  System.out.println("OOOHH--" + exception.toString());


  }


  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux下编译fortran程序_基本菜鸟.. 下一篇Scooter Framework——简化的Java..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: