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

📄 teletype.java

📁 国外的一些较好的APPLET收集(含原码)!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
           Screen = new char[MaxLines][Columns]; /* clean array */           Init_Screen_Array();           update(g);       } //end for   } // end while} // end runpublic void Init_Screen_Array(){   int Lcount, Rcount = 0;   char Temp;   try       {       for(Lcount = 0; Lcount <=MaxLines;Lcount++)       for(Rcount = 0; Rcount <=Columns - 1 ;Rcount++)       {         Temp = ' ';         Screen[Lcount][Rcount] = Temp;       }       }       catch (ArrayIndexOutOfBoundsException e){}} /* Screen array init ends *//* NOTE : The following two routines were modifications of * source distributed at Sunsite.unc.edu. The Author of the * original source is  Elliot Rusty Harold.  * email : elharo@sunsite.unc.edu. * His introduction to java is online at unc and is well  * worth investigation.*//*************************************************//* This routine is used to calculate the maximum *//* number of lines that will be wrapped into     *//* the screen from the message parameters.       *//*************************************************/public void FindMaxLength(String Input_String){  String nextword;  st = new StringTokenizer(Input_String," ");   while (st.hasMoreTokens()) {      nextword = st.nextToken();      if (fm.stringWidth(sb.toString() + nextword) <        (RightMargin - LeftMargin)) {        sb.append(nextword);        sb.append(' ');      }      else if (sb.length() == 0) {        /* do Nothing */      }      else {        if (Columns < sb.length())             Columns = sb.length();        sb = new StringBuffer(nextword + " ");      }    } // end While    if (sb.length() > 0) {     if (Columns < sb.length())             Columns = sb.length();     }      sb = new StringBuffer();      nextword = " " ;  } /*************************************************//* This routine is passed a string. It then      *//* wraps the string by measuring the string      *//* and comparing it to the Display width .       *//* Each time the message is parsed the substring *//* is fed to the data output routine Typer()     *//*************************************************/public void Process_Line(String Input_String){  String nextword;  st = new StringTokenizer(Input_String," ");     while (st.hasMoreTokens()) {      nextword = st.nextToken();      if (fm.stringWidth(sb.toString() + nextword) <        (RightMargin - LeftMargin)) {        sb.append(nextword);        sb.append(' ');      }      else if (sb.length() == 0) {        Typer(nextword); /* catches the one word case */      }      else {        Typer(sb.toString());        sb = new StringBuffer(nextword + " ");      }    } // end While    if (sb.length() > 0) {      Typer(sb.toString());    }      sb = new StringBuffer();      nextword = " ";  } /*************************************************//* This routine is passed the Graphics class     *//* it performas an arraycopy using nested for    *//* loops. The System.arraycopy should work       *//* but created some problems for me.  This       *//* source is my solution and should be easily    *//* adapted for handling two dimesional arrays    *//* for other display techniques.                 *//* All Rights to this routine are mine           */ /*************************************************/public void InsertLine(Graphics g){       int Lcount,Rcount;       char Temp;       char ScrBuff[][] = new char[MaxLines][Columns];               /* Start with each element in the array set to " ".    */       /* This is necessary for Micorsofts Internet Explorer. */       /* IE set's each element to null .........             */              try       {       for(Lcount = 0; Lcount <=MaxLines;Lcount++)       for(Rcount = 0; Rcount <=Columns - 1 ;Rcount++)       {         Temp = ' ';         ScrBuff[Lcount][Rcount] = Temp;       }       }       catch (ArrayIndexOutOfBoundsException e){}       /* That should fix MIE problem */       try       {       for(Lcount = 1; Lcount <=MaxLines;Lcount++)       for(Rcount = 0; Rcount <=Columns - 1 ;Rcount++)       {         Temp = Screen[Lcount][Rcount];         ScrBuff[Lcount-1][Rcount] = Temp;       }       }       catch (ArrayIndexOutOfBoundsException e){}     try       {       for(Lcount = 0; Lcount <=MaxLines-1;Lcount++)       for(Rcount = 0; Rcount <=Columns - 1 ;Rcount++)       {         Temp = ScrBuff[Lcount][Rcount];         Screen[Lcount][Rcount] = Temp;       }       }       catch (ArrayIndexOutOfBoundsException e){}         int insCount;       if(!ImageAvailable)       osg.drawImage(Tube,0,0,size().width,size().height,this);       else       offsnoImage();       for (insCount = 1; insCount <=  MaxLines - 1; insCount ++)       {           osg.drawChars(Screen[insCount -1],0,Columns,CursorX,YLinePos[insCount - 1]);       }       g.drawImage(FinalScreen,0,0,this);  /* Stop Screen Flashing */       CursorX = LeftMargin;       if(!ImageAvailable)       osg.drawImage(Tube,0,0,size().width,size().height,this);/* clear offscreen */       else       offsnoImage();       NumLines = MaxLines-1;try {Thread.sleep(400);}         catch (InterruptedException e){}        } // end Insert Line Routine/********************************************//* This is the scroll routine which can be  *//* used at the end of each message to scroll*//* the characters off the screen. This       *//* routine is also the basis for the Vertical*//* Scroller class here.                     *//********************************************/public void scroller(Graphics g){ int offset =  charHeight / 5; int scrollcount; CursorX = LeftMargin; osg.setFont(Screen_Font); osg.setColor(Screen_Font_Color);   while((YLinePos[NumLines]- offset) >=  - charHeight) {  if(!ImageAvailable)  osg.drawImage(Tube,0,0,size().width,size().height,this);  else  offsnoImage(); for (scrollcount = 0;scrollcount <=NumLines; scrollcount++) {   if (YLinePos[scrollcount] - offset >=  - LineFeed)   osg.drawChars(Screen[scrollcount],0,Columns,CursorX,(YLinePos[scrollcount]-offset)); } //end for offset = offset + charHeight/5; g.drawImage(FinalScreen,0,0,this); try {Thread.sleep(200);}           catch (InterruptedException e){} } // end while  } // end scroller/************************************************//* This is the routine that actually does the   *//* data output tasks. This is my soulution to   *//* the typing text display technique.           *//************************************************/   public void Typer(String InString){       int pcount = 0;       int NumChars = 0;       int TCursorX = LeftMargin;       CursorX = LeftMargin;             if(Life != null){      Graphics g = this.getGraphics();      g.setColor(Screen_Font_Color);      Xlimit = InString.length() - 1;      DisplayMessage = InString.toCharArray();      for (NumChars = 0;NumChars<Xlimit;NumChars++)      {         Screen[NumLines][NumChars] = DisplayMessage[NumChars];      if(!ImageAvailable)      osg.drawImage(Tube,0,0,size().width,size().height,this);      else      offsnoImage();      /***********************************************/      /*  Simply drawing one line at a time should   */      /*  and does work for Netscape 3.0 under Win95.*/      /*  However ; under Netacape 3.0 for Linux the */      /*  characters are not displayed as intended.  */      /*  The solution was to redraw the entire      */      /*  image and screen array for each character. */      /***********************************************/      for (pcount = 0; pcount <=  MaxLines - 1; pcount ++)       {           osg.drawChars(Screen[pcount],0,Columns,TCursorX,YLinePos[pcount]);       }                 CursorX = CursorX + g.getFontMetrics().charsWidth(DisplayMessage,NumChars,1);         try {Thread.sleep(50);}         catch (InterruptedException e){}       g.drawImage(FinalScreen,0,0,this);      } // end For      CursorX = LeftMargin;      CursorY = CursorY + LineFeed;      if(CursorY > YLinePos[MaxLines -1])      {       InsertLine(g);       CursorY = YLinePos[MaxLines -1];       CursorX = LeftMargin;      }      else        NumLines++;      CursorX = LeftMargin;      if(Life !=null) /*Try to catch having left page during the for loop */      {      try {Thread.sleep(100);}         catch (InterruptedException e){}      }         } // end if !done   } /* end Typer*/public void paint(Graphics g){      /****************************************************************/      /* The  loadImageAndWait delay is required to process the image */      /* before characters are displayed . The image is then          */      /* drawn on the display.                                        */      /****************************************************************/      int pcount;      int ThisCursorX = LeftMargin;      g.setFont(Screen_Font);      g.setColor(Screen_Font_Color);      if(getParameter("bgImage") != null)       {        Tube = getImage(getDocumentBase(),BackgroundImage);        if (!set)        {        g.drawString(ImageLoadMessage,20,20);        loadImageAndWait(Tube); /* Prepare image before routines start */        initscreen();        set = true;        initComplete = true;        }       }      else       {         ImageAvailable = true;         offsnoImage();         set = true;         initComplete = true;      }      if (initComplete)      g.drawImage(FinalScreen,0,0,this);   /**************************************************/   /* If the users scrolls down the page and returns */   /* to the applet the entire screen and data are   */   /* reconstructed.                                 */   /**************************************************/   for (pcount = 0; pcount <=  MaxLines - 1; pcount ++)       {           g.drawChars(Screen[pcount],0,Columns,ThisCursorX,YLinePos[pcount]);       }}public void update(Graphics g){       paint(g);}//end updatepublic String getAppletInfo(){      return "teletype / thetube  version 1.3 written by Bill Boulton";}/***************************************************************//*                                                             *//* The Following two routines were "borrowed" from the creator *//* of Instant Java. The site where this and much more code is  *//* available is www.vivids.com.                                *//* These routines get rid of that pesky image not loaded before*//* charcters are displayed problem that has plagued me.        *//* Many thanks to the author of this code.                     *//*                                                             *//***************************************************************/ /**     * Begins the preparation (loading) of the image     * This function returns immediately     * The image is loaded in a thread     *     * @param image the image to prepare     */    public void prepareImage(Image image) {        boolean ImagePrepared;        ImagePrepared = prepareImage(image, this);    }       public synchronized void loadImageAndWait(Image image) {        int checkImageFlags;        boolean ImagePrepared;        ImagePrepared = prepareImage(image, this);        if(ImagePrepared == false) {            while(((checkImageFlags =                    checkImage(image, this)) &                            ImageObserver.ALLBITS) == 0) {                try {                    wait(100);                } catch (InterruptedException e){}            }        }    }     } // end theTube 

⌨️ 快捷键说明

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