/********************************/ /* */ /*   電光掲示板 */ /* */ /* 1998/ 1/24 宍戸 輝光 */ /* */ /********************************/ import java.awt.*; public class keiji extends java.applet.Applet implements Runnable { int x,y,strWidth,size; Image screen,st; Graphics g_screen,g_st; Color bkC,strC,dotC; String str; FontMetrics fm; Thread runner=null; public void init(){ resize(288,96); setBackground(Color.lightGray); st=createImage(256,64); /* 表示板イメージ */ g_st=st.getGraphics(); screen=createImage(264,72); /* 表示用イメージ */ g_screen=screen.getGraphics(); str=getParameter("STR"); /* 引数から文字列を得る */ if (str==null) /* もし文字列が指定されてなければ */ str="Test"; try { /* フォントサイズ */ size=Integer.parseInt(getParameter("SIZE")); } catch (Exception e) { size=32; } g_st.setFont(new Font("TimesRoman",Font.BOLD,size)); fm=getFontMetrics(new Font("TimesRoman",Font.BOLD,size)); strWidth=fm.stringWidth(str); y=64-(64-fm.getAscent())/2; x=256; bkC=new Color(32,32,64); strC=new Color(255,224,160); dotC=new Color(128,96,64); if (runner==null) { runner=new Thread(this); runner.start(); } } public void stop() { /*終了時にスレッド破棄*/ if (runner!=null) { runner.stop(); runner=null; } } public void drawScreen() { int i,j; g_st.setColor(bkC); /* 背景 */ g_st.fillRect(0,0,256,64); g_st.setColor(strC); /* 文字列を書く */ g_st.drawString(str,x,y); g_st.setColor(dotC); for (i=0;i<16;i++) /* ドットを打つ */ for (j=0;j<64;j++) g_st.fillRect(j*4,i*4,1,1); g_screen.setColor(Color.white); /* 掲示板の枠を描く */ g_screen.fillRect(0,0,264,72); g_screen.drawImage(st,4,4,this); repaint(); } public void run() { while (runner!=null) { drawScreen(); try { Thread.sleep(50); } /*ウエイト*/ catch (InterruptedException e) {} x-=3; /* 文字列を左に動かす */ if (x<=-strWidth) /* 左端まで行ったら右端に戻す */ x=256; } } public void paint(Graphics g){ g.drawImage(screen,12,12,this); } public void update(Graphics g){ paint(g); } }