📄 teletype.java
字号:
/* Program : Teletype.java * Purpose : Web Text Display Applet * Author : Bill Boulton * Date : June 12, 1997 * Final Revision July 15 1997 * Version : 1.3 * email : boulton@amadeus.ccs.queensu.ca * Terms : Distribution of this source is being made in the hope that it may be found useful. It can be freely modified and redistributed provided this entire notice is left on the redistribution. * You'll notice that where code is used which was * modified from other source the authors are referenced * as a courtesy and in appreciation of their efforts * to promote "Public Domain" software and the understanding * of the Java Language.*/import java.applet.*;import java.awt.*;import java.util.*;import java.awt.image.*;public class teletype extends Appletimplements Runnable{ String Message[]; int MaxLines; int Columns = 0; int NumLines = 0; char Screen[][]; /* array Malines Columns */ int YLinePos[]; String FontColor; String ImageLoadMessage; int CursorX; int CursorY; int Index=0; int Xlimit=0,LoopCount=0, ArrayCount=0; Thread Life=null; char DisplayMessage[]; String ScrollParam; boolean ScrollFlag = true; boolean set = false; String BackgroundImage; Image Tube; boolean ImageAvailable = false; Color BackColor; String Bgcolor; String MessageParms; /* Have the user supply the number of messages */ int NumMessages; /* Valid between 1 and 5 (msg0 to msg4). *//**************************/ /* */ /* Offscreen graphics *//* Variables *//* *//**************************/Image FinalScreen; Graphics osg; /**************************/ /* */ /* Screen graphics *//* Variables *//* *//**************************/Graphics g;boolean initComplete = false;/**************************//* Font Variables *//**************************/ Font Screen_Font; Font normalFont; FontMetrics fm; Color Screen_Font_Color; /* Parameter from html tag */ private int charWidth; private int charHeight; private int charDescent; private int LineFeed;/************************//* Screen Margins *//************************/ private int TopMargin; private int LeftMargin; private int RightMargin; private int BottomMargin;/*****************************************//* Variabeles used to wrap the Messages *//* to which fit into the Display *//* area. *//*****************************************/ StringBuffer sb = new StringBuffer(); StringTokenizer st; String Line[]; public void init(){ BackgroundImage =getParameter("bgImage"); g=this.getGraphics(); MessageParms = getParameter("Msgnum"); NumMessages =(MessageParms ==null)? 2 :Integer.parseInt(MessageParms); Message = new String[NumMessages]; Message[0] = getParameter("Msg0"); if (NumMessages > 1) Message[1] = getParameter("Msg1"); if (NumMessages > 2) Message[2]= getParameter("Msg2"); if (NumMessages > 3) Message[3]= getParameter("Msg3"); if (NumMessages > 4) Message[4]= getParameter("Msg4"); ImageLoadMessage="Loading Image"; resize(size().width, size().height); Screen_Font= initFont(); setFont(Screen_Font); fm = getFontMetrics(Screen_Font); if(fm != null) { charWidth = fm.charWidth(' '); charHeight = fm.getHeight(); charDescent = fm.getDescent(); } LineFeed = charHeight + 1; LeftMargin = 18; RightMargin = size().width - 15; TopMargin = 32; BottomMargin = size().height - 25; CursorY = TopMargin; CursorX = LeftMargin; MaxLines = (size().height - TopMargin) / (LineFeed); YLinePos = new int[MaxLines]; /*************************************************/ /* */ /* Set up the Line Y positions. */ /* These positions are used by the Insert */ /* Line routine to draw the Strings */ /* */ /*************************************************/ for (LoopCount = 0; LoopCount <MaxLines;LoopCount++) { if (LoopCount == 0) YLinePos[LoopCount] = CursorY; else YLinePos[LoopCount] = YLinePos[LoopCount -1] + LineFeed ; } /*************************************************/ /* */ /* Find the Maximum Number of */ /* Characters that will fit into the */ /* Screen Area. */ /* This is used to define the number */ /* of columns in the screen. */ /* */ /*************************************************/ for (LoopCount = 0; LoopCount < NumMessages-1;LoopCount++) FindMaxLength(Message[LoopCount]); Screen = new char[MaxLines][Columns]; /* establish screen size */ Init_Screen_Array(); /* Microsoft ie need this */ if (getParameter("Scroll") != null) { ScrollParam = getParameter("Scroll"); if(ScrollParam.equalsIgnoreCase("no")) ScrollFlag = false; } else ScrollFlag = true; if(getParameter("Colour") != null) { FontColor = getParameter("Colour"); Screen_Font_Color = Set_Color(FontColor); } else Screen_Font_Color = Color.yellow; if(getParameter("Bg") != null) { Bgcolor = getParameter("Bg"); BackColor = Set_Color(Bgcolor); } else BackColor = Color.black; setBackground(BackColor); FinalScreen = createImage(size().width,size().height ); osg = FinalScreen.getGraphics(); osg.setColor(Screen_Font_Color); osg.setFont(Screen_Font); } // end init/*********************************//* The Following two routines *//* are used to set the background*//* to a solid color if no image *//* is provided. *//*********************************/ public void offsnoImage(){ osg.setColor(BackColor); osg.fillRect(0,0,size().width,size().height); osg.setColor (Screen_Font_Color);}public void mainnoImage(){ g.setColor(BackColor); g.fillRect(0,0,size().width,size().height); g.setColor (Screen_Font_Color);} /********************************************************//* This routine was designed to return a color *//* for a given parameter. *//* The default color is green. This generic *//* module can be easily imported into any other *//* Progam. *//********************************************************/ public Color Set_Color(String Target){ if (Target.equalsIgnoreCase("black")) return( Color.black); else if (Target.equalsIgnoreCase("white")) return(Color.white); else if (Target.equalsIgnoreCase("gray")) return(Color.gray); else if (Target.equalsIgnoreCase("red")) return(Color.red); else if (Target.equalsIgnoreCase("green")) 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 */ } }public void initscreen(){ osg.setColor(Screen_Font_Color); osg.setFont(Screen_Font); if(!ImageAvailable) osg.drawImage(Tube,0,0,size().width,size().height,this); else offsnoImage();} 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(){ Screen = new char[MaxLines][Columns]; /* clean array */ Init_Screen_Array(); set = false; CursorX = LeftMargin; NumLines = 0; Life.stop(); Life=null; } public void run(){ int Count; while(Life!=null){ if(Life !=null) update(g); for (Count = 0; Count <= NumMessages -1; Count++) { NumLines = 0; CursorY = TopMargin; CursorX = LeftMargin; Process_Line(Message[Count]); try {Thread.sleep(600);} catch (InterruptedException e){} if(ScrollFlag) scroller(g);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -