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

📄 scrolltext.java

📁 Applet Name: Scroll Text Applet Source: ScrollText.java Import(s): java.awt, java.lang, java.uti
💻 JAVA
字号:
//////////////////////////////////////////////////////

//

// ScrollText.java

//

// Author: Bradley Birnbaum (birnbaum@imsworld.com)

// Description: A java applet that scrolls text

//      in a similar fashion to the traditional

//      stock ticker tape.

// Parameters: text - the message that you would like

//      to display

//

// Copyright 1995-1996, Bradley Birnbaum

//

/////////////////////////////////////////////////////



import java.applet.Applet;

import java.awt.*;

import java.util.*;

import java.lang.*;



public class ScrollText extends Applet implements Runnable {



  String s, num;

  Thread killme = null;

  long j,length;

  int tmp;

  Font font, smfont;

  boolean threadSuspended = false;

  Image newImage;

  Graphics newGraphics;

  Dimension newSize;

  Date dt;





  public String getAppletInfo(){

    return "Ticker Tape, Copyright 1995-1996, Bradley Birnbaum";

  }



  public void init() {

    resize(400,50);

    font= new Font("TimesRoman",Font.PLAIN,12);

    smfont= new Font("TimesRoman",Font.PLAIN,10);

    setFont(new Font("TimesRoman",Font.PLAIN,12));

    s = getParameter("text");

    if(s==null)

      s="There was no text entered";



  }



  public void start() {

    if(killme == null)

      {

        killme = new Thread(this);

        killme.start();

      }

  }



  public void stop() {

    killme = null;

  }



  public void run() {

    j=size().width;

    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);



    while (killme != null) {

      try {Thread.sleep(15);} catch (InterruptedException e){}



      repaint();

      j--;

      if (j+length+15<0){

        j=size().width;

      }

    }

    killme = null;

  }





  public synchronized void update (Graphics newG)

    {

      Dimension d = size();



      if((newImage == null) || (d.width != newSize.width) ||

         (d.height != newSize.height))

        {

          newImage = createImage(d.width, d.height);

          newSize = d;

          newGraphics = newImage.getGraphics();

          newGraphics.setFont(getFont());

        }

      paint(newGraphics);

      newG.drawImage(newImage, 0, 0, null);

    }







  public void paint(Graphics g) {

    g.setColor(Color.yellow);

    g.fill3DRect(0,0,size().width,size().height,true);

    g.setColor(Color.black);

    g.setFont(smfont);

    g.drawString("Ticker Tape, Copyright 1995-1996, Bradley Birnbaum",5,12);

    g.setColor(Color.red);

    g.drawString(getTime(),360,12);

    g.setColor(Color.black);

    g.fillRect(0,15,size().width,size().height-20);

    g.setFont(font);

    FontMetrics fm=g.getFontMetrics();

    length=fm.stringWidth(s);

    g.setColor(Color.white);

    g.drawString(s,(int)j,32);

  }





  public String getTime(){

    StringBuffer date = new StringBuffer();

    Date dt = new Date();

    date.append(dt.getHours()+":");

    tmp=dt.getMinutes();

    if(tmp < 10)date.append("0");

    date.append(tmp+":");

    tmp=dt.getSeconds();

    if(tmp < 10)date=date.append("0");

    date.append(tmp);

    return date.toString();



  }







  public boolean mouseDown(java.awt.Event evt, int x, int y) {

    if (threadSuspended) {

      killme.resume();

    }

    else {

      killme.suspend();

    }

    threadSuspended = !threadSuspended;

    return true;

  }





}







⌨️ 快捷键说明

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