scrollingsimple.java

来自「java语言与面向对象程序设计源程序」· Java 代码 · 共 39 行

JAVA
39
字号
//<applet code=ScrollingSimple.class width=200 height=80>
//</applet>
import java.applet.Applet;
import java.awt.TextField;
public class ScrollingSimple extends Applet {
   TextField field;
   public void init( ) {
       //Create the text field and make it uneditable.
     field = new TextField( );
     field.setEditable(false);
         /*Set the layout manager so that the text field will be 
         as wide as possible. */
     setLayout(new java.awt.GridLayout(1,0));
         //Add the text field to the applet.
     add(field);
     validate( );
     addItem("initializing…");
     }
   public void start() {
     addItem("starting…");
   }
   public void stop() {
     addItem("stopping…");
   }
   public void destroy( ) {
      addItem("preparing for unloading…");
   }
   void addItem(String newWord) {
      int k= newWord.length();
      String t = field.getText();
      if( t.length() > k+20)
       { t= t.substring(k-1);};
         System.out.println(newWord);
         field.setText(t + newWord);
         repaint();
       }
   }

⌨️ 快捷键说明

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