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

📄 vscroller.java

📁 国外的一些较好的APPLET收集(含原码)!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return(Color.green);      else if (Target.equalsIgnoreCase("blue"))        return(Color.blue);      else if (Target.equalsIgnoreCase("yellow"))        return(Color.yellow);      else if (Target.equalsIgnoreCase("orange"))        return(Color.orange);      else if (Target.equalsIgnoreCase("magenta"))        return(Color.magenta);      else if (Target.equalsIgnoreCase("pink"))        return(Color.pink);      else if (Target.equalsIgnoreCase("cyan"))        return(Color.cyan);      else      {         try{            return(new Color(Integer.parseInt(Target, 16)));}         catch (NumberFormatException e)            {return( Color.yellow); }/* Default FontColor not valid */       }          }/* This routine simply returns a font for our use */   public Font initFont()   {        String fontname;        String fontstyle;          int style = -1;        int points;        Font font;        Font defaultfont;        String pointstring;        defaultfont = getFont();        fontname = getParameter("Font");        if(fontname == null)            fontname = defaultfont.getName();        fontstyle = getParameter("Style");        if(fontstyle == null)            style = defaultfont.getStyle();        // Get the Font        if(fontname.equalsIgnoreCase("TimesRoman")  ||           fontname.equalsIgnoreCase("Helvetica")   ||           fontname.equalsIgnoreCase("Courier") )           {                // Nothing to do the fontname is supported           }        else           {               fontname = defaultfont.getName();           }        if(style == -1) {            // Get the Font Style            if(fontstyle.equalsIgnoreCase("bold"))                style = Font.BOLD;            else if(fontstyle.equalsIgnoreCase("italic"))                style = Font.ITALIC;            else if(fontstyle.equalsIgnoreCase("bolditalic"))                style = Font.ITALIC|Font.BOLD;            else                style = Font.PLAIN;        }        pointstring = getParameter("Points");        if(pointstring == null)            points = defaultfont.getSize();        else {            try {                points = Integer.parseInt(pointstring);            } catch (NumberFormatException e) {                points = defaultfont.getSize();                            }        }                              font = new Font(fontname, style, points);        return font;    }          public void start(){      if(Life==null){         Life=new Thread(this);         Life.start();               }   }   public void stop(){      Life.stop();      Life=null;      } public void run(){      Thread.currentThread().setPriority(Thread.MIN_PRIORITY);      while(Life!=null){      int FinalY = 0;      int Count= 0;      String msg = " ";      for (Count = 0; Count <= NumMessages-1; Count++)       {           offset = -2*charHeight;           CursorX = LeftMargin;           NumLines = 0;              try{           Process_Line(Message[Count]); // set the screen character array           }           catch(ArrayIndexOutOfBoundsException e)           {g.drawString("run count out of bounds",20,20);}           FinalY =(NumLines *(LineFeed+charHeight));           if (NumLines == MaxLines -1)           FinalY = FinalY - 2*(LineFeed+charHeight); // try to reduce the delay)           if(ScrollFlag)           while(!MsgDone )           {                           update(g);             offset = offset + charHeight/Divisor;             try {Thread.sleep(Delay);}                 catch (InterruptedException e){}                         if (FinalY - offset <= 0)                    MsgDone = true;           } //end while           Screen = new char[MaxLines][Columns]; /* clean array */           Init_Screen_Array();           MsgDone = false;           FinalY = 0;       } // end for       }}// end runpublic synchronized void paint(Graphics g){ int scrollcount; CursorX = LeftMargin; osg.setFont(Screen_Font); osg.setColor(Screen_Font_Color);   if(!set)     {  if(getParameter("bgImage") != null)     {      set = true;      Tube = getImage(getDocumentBase(),BackgroundImage);      loadImageAndWait(Tube); /* Prepare image before routines start */      initscreen();      g.drawString(ImageLoadMessage,20,20);                     }      else       {         ImageAvailable = true;         set = true;         initscreen();      }  } // end if not set  if(!ImageAvailable)  osg.drawImage(Tube,0,0,size().width,size().height,this);  else  offsnoImage();  try  { for (scrollcount = 0;scrollcount <= NumLines-1;  scrollcount++) {   if(YLinePos[scrollcount] - offset <= size().height + 2*charHeight)   {    if (YLinePos[scrollcount] - offset >= - charHeight)   osg.drawChars(Screen[scrollcount],0,Columns,CursorX,(YLinePos[scrollcount]-offset));   } } //end for } catch (ArrayIndexOutOfBoundsException e){}g.drawImage(FinalScreen,0,0,this);} // end paint public void FindMaxLength(String Input_String){  st = new StringTokenizer(Input_String," ");  int Lines = 0;   while (st.hasMoreTokens()) {      String nextword = st.nextToken();      if (fm.stringWidth(sb.toString() + nextword) <        (RightMargin - LeftMargin)) {        sb.append(nextword);        sb.append(' ');      }      else if (sb.length() == 0) {         Lines++;         if(Lines>MaxLines)         MaxLines = Lines;       }      else {        if (Columns < sb.length())             Columns = sb.length();        Lines++ ;        if (Lines > MaxLines)        MaxLines = Lines;        sb = new StringBuffer(nextword + " ");      }    } // end While    if (sb.length() > 0) {     if (Columns < sb.length())     {             Columns = sb.length();             Lines++;             MaxLines = Lines;                  }    }      sb = new StringBuffer();      MaxLines++;  } // end find max length/*************************************************//* This routine is passed a string. It then      *//* wraps the string by measuring the string      *//* and comparing it to the Display width         *//* This portion is a modified copy of the source *//* available from sunsite.unc.edu written by     *//* Eliotte Rusty Harold elharo@susnite.unc.edu.  *//* All Rights to this routine belong to Elliote. */ /*************************************************/public void Process_Line(String Input_String){   st = new StringTokenizer(Input_String," ");   while (st.hasMoreTokens()) {      String 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 */         if(NumLines <MaxLines)         NumLines++;      }      else {        Typer(sb.toString());         if(NumLines <MaxLines)         NumLines++;        sb = new StringBuffer(nextword + " ");      }    } // end While    if (sb.length() > 0) {      Typer(sb.toString());       if(NumLines <MaxLines)       NumLines++;    }      sb = new StringBuffer();  } /************************************************//* This is the routine that actually does the   *//* character insertion task. Placing the        *//* characters in the screen[][] array.          *//************************************************/   public void Typer(String InString){      if(Life != null){      Xlimit = InString.length() - 1;           DisplayMessage = InString.toCharArray();      try      {      for (NumChars = 0;NumChars<Xlimit;NumChars++)      {               Screen[NumLines][NumChars] = DisplayMessage[NumChars];               } // end For      }     catch(ArrayIndexOutOfBoundsException e)         {         };                                     } // end if !done} /* end Typer*/public synchronized void update(Graphics g){       paint(g);}//end updatepublic String getAppletInfo(){      return "Scroller  version 1.0 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 scroller 

⌨️ 快捷键说明

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