[ java ] in KIDS 글 쓴 이(By): ThisCase () 날 짜 (Date): 1997년11월12일(수) 10시04분56초 ROK 제 목(Title): 프로젝트2 : 아주간단히.... import java.awt.*; import java.applet.Applet; public class ScrollText1 extends Applet implements Runnable{ String Text[]; int n; Color ColorArray[]; Font textFont; FontMetricstextFontMetrics; int charMaxHeight; int Height,Width; Thread thread; Image offImage; Graphics offGraphics; int starty,endy; int gap = 0; int speed = 1; int totalHeight; public void init(){ n = Integer.parseInt(getParameter("TextNum")); Text = new String[n]; thread = new Thread(this); for(int i = 0;i < n;i++){ Text[i] = getParameter("Text" + i); } textFont = new java.awt.Font("Helvetica",Font.BOLD,12); /* font를 지정 */ textFontMetrics = getFontMetrics(textFont); /* font의 특성을 저장 */ charMaxHeight = textFontMetrics.getLeading() + textFontMetrics.getMaxAscent() + textFontMetrics.getMaxDescent(); ColorArray = new Color[10]; ColorArray[0] = new Color(0,0,99); ColorArray[1] = new Color(214,132,0); ColorArray[2] = new Color(107,0,33); ColorArray[3] = new Color(99,49,0); ColorArray[4] = new Color(0,49,0); ColorArray[5] = new Color(0,99,99); ColorArray[6] = new Color(49,0,49); ColorArray[7] = new Color(206,49,0); ColorArray[8] = new Color(87,14,14); ColorArray[9] = new Color(172,87,4); Dimension d = size(); Height = d.height; Width = d.width; totalHeight = n * (charMaxHeight + gap); if(offGraphics == null){ offImage = createImage(Width,totalHeight + Height * 2); offGraphics = offImage.getGraphics(); } offGraphics.setColor(Color.white); offGraphics.fillRect(0,0,Width,totalHeight + Height * 2); starty = Height; for(int i = 0;i < n;i++){ offGraphics.setColor(ColorArray[i]); offGraphics.drawString(Text[i],5,starty + (charMaxHeight + gap) * i); } starty = 0; } public void start(){ if(thread.isAlive()){ thread.resume(); } else{ thread.start(); } } public void stop(){ thread.suspend(); } public void destory(){ thread.stop(); } public void run(){ while(true){ repaint(); try{ thread.sleep(100); } catch(InterruptedException e){ } } } public void paint(Graphics g){ g.drawImage(offImage,0,starty,null); starty -= speed; if(starty <= -(totalHeight + Height)){ starty = 0; } } } |