home *** CD-ROM | disk | FTP | other *** search
Java Source | 2017-09-21 | 13.0 KB | 509 lines |
- /*
- *
- * NeonSign.java 1.00 96/02/15 S.Nakagawa
- *
- * Copyright (c) 1996 KOTOBUKI SYSTEM CO.,LTD. All Rights Reserved.
- *
- * ï@ö\ : ÄwÆΦé│éΩé╜âpâ^ü[âôâtâ@âCâïé╔ôoÿ^é│éΩé─éóéΘâpâ^ü[âôé≡ôdî⌡îfĪé╖éΘüB
- *
- * âpâëâüü[â^ : patfile âpâ^ü[âôâtâ@âCâïû╝é≡ÄwÆΦé╖éΘüB
- * backcolor ôdî⌡îfĪö┬é╠öwîié╠ÉFé≡ÄwÆΦé╖éΘüB
- * "r,g,b"é╠Åçé┼ÄwÆΦé╖éΘüB
- * Å╚ù¬Ä₧é═üA"0,0,0" é╞é╖éΘüB
- * lightcolor ôdïàé¬ô_éóé─éóéΘÅΩìçé╠ÉFé≡ÄwÆΦé╖éΘüB
- * "r,g,b"é╠Åçé┼ÄwÆΦé╖éΘüB
- * Å╚ù¬Ä₧é═üA"255,255,0" é╞é╖éΘüB
- * outcolor ôdïàé¬Å┴éªé─éóéΘÅΩìçé╠ÉFé≡ÄwÆΦé╖éΘüB
- * "r,g,b"é╠Åçé┼ÄwÆΦé╖éΘüB
- * Å╚ù¬Ä₧é═üA"204,204,0" é╞é╖éΘüB
- * lightsize ôdïàé╠âTâCâYé≡ÄwÆΦé╖éΘüB
- * Å╚ù¬Ä₧é═üA5 é╞é╖éΘüB
- * òKé╕ 2 ê╚Åπé≡ÄwÆΦé╡é╚é»éΩé╬éóé»é╚éóüB
- * lightbetw ôdïàè╘é╠âTâCâYé≡ÄwÆΦé╖éΘüB
- * Å╚ù¬Ä₧é═üA2 é╞é╖éΘüB
- * scroll ôdî⌡îfĪö┬é╠âXâNâìü[âïæ¼ôxé≡ôdïàé╠î┬Éöé┼ÄwÆΦé╖éΘüB
- * Å╚ù¬Ä₧é═üA1 é╞é╖éΘüB
- * speed ôdî⌡îfĪö┬é╠ăé╠âXâNâìü[âïé▄é┼é╠Ä₧è╘é≡â~âèòbé┼ÄwÆΦé╖éΘüB
- * Å╚ù¬Ä₧é═üA100 é╞é╖éΘüB
- *
- * Ägùpùß : <APPLET CODE="NeonSign.class" WIDTH=300 HEIGHT=300>
- * <PARAM NAME=PATFILE VALUE="..\Java\sign.dat">
- * <PARAM NAME=BACKCOLOR VALUE="0,0,0">
- * <PARAM NAME=LIGHTCOLOR VALUE="255,255,0">
- * <PARAM NAME=OUTCOLOR VALUE="204,204,0">
- * <PARAM NAME=LIGHTSIZE VALUE=5>
- * <PARAM NAME=LIGHTBETW VALUE=2>
- * <PARAM NAME=SCROLL VALUE=1>
- * <PARAM NAME=SPEED VALUE=100>
- * </APPLET>
- */
- import java.applet.Applet;
- import java.awt.Image;
- import java.awt.Event;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Component;
- import java.lang.System;
- import java.util.StringTokenizer;
- import java.io.InputStream;
- import java.io.DataInputStream;
- import java.net.URL;
- //import java.net.MalformedURLException;
-
-
- /*
- * NeonSign Class.
- *
- * ì∞ɼÄ╥ : S.Nakagawa
- * Version : 1.00 96/02/15
- */
- public
- class NeonSign extends Applet implements Runnable
- {
- /*
- * âvâìâZâXüAâXâîâbâhè╓ÿA
- */
- Thread engine = null; /* âXâîâbâhÅεò± */
- boolean threadSuspended = false; /* âXâîâbâhÆΓÄ~âtâëâO */
- int errorCode = 0; /* âGâëü[ö╘ìå */
-
- /*
- * âIâtâXâNâèü[âôù╠êµ
- */
- Graphics offScrGraph; /* âCâüü[âWüEâRâôâeâLâXâg */
- Image offScrImage; /* âCâüü[âWÅεò± */
-
- /*
- * ôdî⌡îfĪö┬ò\Īâpâ^ü[âô
- */
- int patCount; /* âpâ^ü[âôî┬Éö */
- int patHeight; /* âpâ^ü[âôé╠ìéé│ */
- int patWidth; /* âpâ^ü[âôé╠ò¥ */
- char patChar; /* ùLî°ò╢ÄÜ */
- Graphics neonScrGraph; /* âCâüü[âWüEâRâôâeâLâXâg */
- Image neonScrImage; /* âCâüü[âWÅεò± */
- int neonWidth; /* âCâüü[âWüEâTâCâY */
- int neonHeight; /* âCâüü[âWüEâTâCâY */
- int neonPos = 0; /* ò\ĪèJÄnê╩Æu */
-
- /*
- * âpâëâüü[â^
- */
- String patFile; /* âpâ^ü[âôâtâ@âCâïû╝ */
- Color backColor; /* ôdî⌡îfĪö┬öwîiÉF */
- Color lightColor; /* ôdïàô_ôòÉF */
- Color outColor; /* ôdïàÅ┴ôòÉF */
- int lightSize; /* ôdïàâTâCâY */
- int lightBetw; /* ôdïàè╘âTâCâY */
- int scroll; /* âXâNâìü[âïæ¼ôx */
- int speed; /* ăé╠âXâNâìü[âïé▄é┼é╠Ä₧è╘ */
-
-
- /*
- * Åëè·Åêù¥
- * <PARAM NAME=....>éµéΦôné│éΩé╜âpâëâüü[â^é≡ĵô╛é╖éΘüB
- * ĵô╛é╡é╜âpâëâüü[â^âtâ@âCâïé⌐éτâpâ^ü[âôé≡ÆèÅoé╖éΘüB
- * âIâtâXâNâèü[âôé╔ôdî⌡îfĪö┬é≡ì∞ɼé╖éΘüB
- */
- public void init()
- {
- InputStream is; /* âtâ@âCâïüEâXâgâèü[âÇ */
- int keyEnd; /* îƒì⌡ò╢ÄÜê╩Æu */
- int red; /* É╘ÉFö╘ìå */
- int green; /* ù╬ÉFö╘ìå */
- int blue; /* É┬ÉFö╘ìå */
- StringTokenizer st; /* âtâHü[â}âbâgòté½ò╢ÄÜù± */
-
-
- /*
- * âpâëâüü[â^é≡ĵô╛é╖éΘ
- */
- /* âpâ^ü[âôâtâ@âCâïû╝ */
- patFile = getParameter( "patfile" );
- if ( patFile == null )
- {
- errorCode = 1;
- return ;
- }
-
- /* ôdî⌡îfĪö┬öwîiÉF */
- String at = getParameter( "backcolor" );
- if ( at == null )
- {
- backColor = new Color( 0, 0, 0 );
- }
- else
- {
- keyEnd = at.indexOf( "," );
- red = Integer.valueOf( at.substring( 0, keyEnd ) ).intValue();
- st = new StringTokenizer( at.substring( keyEnd + 1 ), "," );
- green = Integer.valueOf( st.nextToken() ).intValue();
- blue = Integer.valueOf( st.nextToken() ).intValue();
- backColor = new Color( red, green, blue );
- }
-
- /* ôdïàô_ôòÉF */
- at = getParameter( "lightcolor" );
- if ( at == null )
- {
- lightColor = new Color( 255, 255, 0 );
- }
- else
- {
- keyEnd = at.indexOf( "," );
- red = Integer.valueOf( at.substring( 0, keyEnd ) ).intValue();
- st = new StringTokenizer( at.substring( keyEnd + 1 ), "," );
- green = Integer.valueOf( st.nextToken() ).intValue();
- blue = Integer.valueOf( st.nextToken() ).intValue();
- lightColor = new Color( red, green, blue );
- }
-
- /* ôdïàô_Å┴ôò */
- at = getParameter( "outcolor" );
- if ( at == null )
- {
- outColor = new Color( 102, 102, 102 );
- }
- else
- {
- keyEnd = at.indexOf( "," );
- red = Integer.valueOf( at.substring( 0, keyEnd ) ).intValue();
- st = new StringTokenizer( at.substring( keyEnd + 1 ), "," );
- green = Integer.valueOf( st.nextToken() ).intValue();
- blue = Integer.valueOf( st.nextToken() ).intValue();
- outColor = new Color( red, green, blue );
- }
-
- /* ôdïàâTâCâY */
- at = getParameter( "lightsize" );
- lightSize = ( at != null ) ? Integer.valueOf(at).intValue() : 5;
-
- /* ôdïàè╘âTâCâY */
- at = getParameter( "lightbetw" );
- lightBetw = ( at != null ) ? Integer.valueOf(at).intValue() : 3;
-
- /* âXâNâìü[âïæ¼ôx */
- at = getParameter( "scroll" );
- scroll = ( at != null ) ? Integer.valueOf(at).intValue() : 1;
-
- /* ăé╠âXâNâìü[âïé▄é┼é╠Ä₧è╘ */
- at = getParameter( "speed" );
- speed = ( at != null ) ? Integer.valueOf(at).intValue() : 100;
-
- /*
- * âIâtâXâNâèü[âôé╔ôdî⌡îfĪö┬é≡ì∞ɼé╖éΘ
- */
- /* âpâ^ü[âôâtâ@âCâïé≡âIü[âvâôé╖éΘ */
- try {
- is = new URL( getDocumentBase(), patFile ).openStream();
- } catch ( Exception e ) {
- errorCode = 2;
- return ;
- }
-
- /* âpâ^ü[âôâtâ@âCâïé¬âIü[âvâôÅoùêé╚éóÅΩìçüAâvâìâZâXé≡ÆåÆfé╖éΘ */
- if ( is == null )
- {
- errorCode = 2;
- return ;
- }
-
- /* âXâgâèü[âÇé≡ë₧ùpé╠ùÿé¡î`é╔ò╧éªéΘ */
- DataInputStream ds = new DataInputStream( is );
-
- /* âtâ@âCâïé╠ɵô¬é╔éáéΘâRâüâôâgìsïyé╤ï≤öÆìsé≡ô╟é▌ö≥é╬é╖ */
- String lineBuffer;
- while ( true )
- {
- try {
- lineBuffer = ds.readLine();
- } catch ( Exception e ) {
- try {
- is.close();
- } catch ( Exception e2 ) {
- };
- errorCode = 3;
- return ;
- }
- if ( ( lineBuffer == null ) || ( lineBuffer.length() != 0 && lineBuffer.charAt( 0 ) != '#' ) ) break;
- }
-
- /* EOFé╠ÅΩìçüAÅêù¥é╡é╚éó */
- if ( lineBuffer == null )
- {
- try {
- is.close();
- } catch ( Exception e ) {
- };
- errorCode = 3;
- return ;
- }
-
- /* âpâ^ü[âôâtâ@âCâïé┼é═é╚éóÅΩìçüAÅêù¥é╡é╚éó */
- if ( lineBuffer.charAt( 0 ) != 'S' && lineBuffer.charAt( 0 ) != 's' )
- {
- try {
- is.close();
- } catch ( Exception e ) {
- };
- errorCode = 3;
- return ;
- }
-
- /* âLü[âÅü[âhÅIù╣ê╩Æué≡ĵô╛é╖éΘ */
- keyEnd = lineBuffer.indexOf( " " );
-
- /* âtâHü[â}âbâgòté½é╠ò╢ÄÜù±é≡ì∞ɼé╖éΘ */
- st = new StringTokenizer( lineBuffer.substring( keyEnd + 1 ), " " );
-
- /* âpâ^ü[âôé╠î┬Éöé≡ĵô╛é╖éΘ */
- patCount = Integer.valueOf( st.nextToken() ).intValue();
-
- /* âpâ^ü[âôé╠ìéé│é≡ĵô╛é╖éΘ */
- patHeight = Integer.valueOf( st.nextToken() ).intValue();
-
- /* âpâ^ü[âôé╠ò¥é≡ĵô╛é╖éΘ */
- patWidth = Integer.valueOf( st.nextToken() ).intValue();
-
- /* ôdî⌡îfĪö┬ù╠êµé≡èmò█é╖éΘ */
- neonWidth = ( patWidth * patCount * lightSize ) + ( patWidth * patCount * lightBetw );
- neonHeight = ( patHeight * lightSize ) + ( ( patHeight + 1 ) * lightBetw );
- neonScrImage = createImage( neonWidth, neonHeight );
- neonScrGraph = neonScrImage.getGraphics();
-
- /* öwîiÉFé≡É▌ÆΦé╡üAæSæ╠é≡ôhéΦé┬é╘é╖ */
- neonScrGraph.setColor( backColor );
- neonScrGraph.fillRect( 0, 0, neonWidth, neonHeight );
-
- /* ôdî⌡îfĪâpâ^ü[âôì∞ɼâïü[âv */
- int i = 0, j = 0;
- while ( true )
- {
- /* âpâ^ü[âôâfü[â^é≡ô╟é▌ì₧é▐ */
- try {
- lineBuffer = ds.readLine();
- } catch ( Exception e ) {
- try {
- is.close();
- } catch ( Exception e2 ) {
- };
- errorCode = 4;
- return ;
- }
-
- /* EOFé╚éτâïü[âvé≡ö▓é»éΘ */
- if ( lineBuffer == null ) break;
-
- /* âRâüâôâgìsûöé═ï≤öÆìsé═ô╟é▌ö≥é╬é╖ */
- if ( lineBuffer.length() == 0 || lineBuffer.charAt( 0 ) == '#' ) continue;
-
- /* âpâ^ü[âôâfü[â^é┼é╚éóÅΩìçüAÅêù¥é╡é╚éó */
- if ( lineBuffer.charAt( 0 ) != 'P' && lineBuffer.charAt( 0 ) != 'p' )
- {
- try {
- is.close();
- } catch ( Exception e ) {
- };
- errorCode = 3;
- return ;
- }
-
- /* âLü[âÅü[âhÅIù╣ê╩Æué≡ĵô╛é╖éΘ */
- keyEnd = lineBuffer.indexOf( " " );
-
- /* âpâ^ü[âôâfü[â^ò╢ÄÜù±é≡ì∞ɼé╖éΘ */
- String patData = new String( lineBuffer.substring( keyEnd + 1 ) );
-
- /* âpâ^ü[âôâfü[â^é╠ò¥é¬"S"é┼ÄwÆΦé│éΩé╜ò¥é╞ê┘é╚éΘÅΩìçüAÅêù¥é╡é╚éó */
- if ( patData.length() != patWidth )
- {
- try {
- is.close();
- } catch ( Exception e ) {
- };
- errorCode = 5;
- return ;
- }
-
- /* âpâ^ü[âôâeü[âuâïé╔É▌ÆΦé╖éΘ */
- for ( int k = 0; k < patWidth; k++ )
- {
- int x = ( lightSize * ( ( patWidth * i ) + k ) ) +
- ( lightBetw * ( ( patWidth * i ) + k + 1 ) );
- int y = ( lightSize * j ) +
- ( lightBetw * ( j + 1 ) );
-
- if ( patData.charAt( k ) == ' ' )
- {
- neonScrGraph.setColor( lightColor );
- if ( lightSize == 1 )
- {
- neonScrGraph.fillRect( x, y, lightSize, lightSize );
- }
- else
- {
- neonScrGraph.fillArc( x, y, lightSize, lightSize, 0, 0 );
- }
-
- }
- else
- {
- neonScrGraph.setColor( outColor );
- if ( lightSize == 1 )
- {
- neonScrGraph.fillRect( x, y, lightSize, lightSize );
- }
- else
- {
- neonScrGraph.fillArc( x, y, lightSize, lightSize, 0, 0 );
- }
- }
- }
-
- /* âeü[âuâïö╘ìåé≡ìXÉVé╖éΘ */
- if ( ++j == patHeight )
- {
- j = 0;
- if ( ++i == patCount ) break;
- }
- }
-
- /* âpâ^ü[âôâtâ@âCâïé≡âNâìü[âYé╖éΘ */
- try {
- is.close();
- } catch ( Exception e ) {
- };
-
- /* âIâtâXâNâèü[âôé≡ì∞ɼé╖éΘ */
- offScrImage = createImage( size().width, size().height );
- offScrGraph = offScrImage.getGraphics();
- offScrGraph.fillRect( 0, 0, size().width, size().height );
- }
-
- /*
- * âüâCâôÅêù¥
- * âpâ^ü[âôâtâ@âCâïé╔ÄwÆΦé│éΩé╜âpâ^ü[âôé≡âXâNâìü[âïé│é╣é╚é¬éτò\Īé╖éΘüB
- */
- public void run()
- {
- /* è∙é╔âGâëü[é¬ö¡É╢é╡é─éóéΘÅΩìçüAÅêù¥é╡é╚éó */
- if ( errorCode != 0 )
- {
- switch ( errorCode )
- {
- case 1: showStatus( "pattern file name not appoint!!" );
- break;
- case 2: showStatus( "pattern file can't open!! \"" + patFile + "\"" );
- break;
- case 3: showStatus( "appoint file is not pattern file!! \"" + patFile + "\"" );
- break;
- case 4: showStatus( "pattern file read error!! \"" + patFile + "\"" );
- break;
- default: showStatus( "pattern width is not enough!! \"" + patFile + "\"" );
- break;
- }
- return ;
- }
-
- /* î╗âXâîâbâhé╠ùDɵÅçê╩é≡É▌ÆΦé╖éΘ */
- Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
-
- /* ò`ëµâXâîâbâhÅIù╣âgâèâKü[é¬É▌ÆΦé│éΩé─éóé╚éóÅΩìçé╔âïü[âvé╖éΘ */
- while ( engine != null )
- {
- /* ì─ò`ëµ */
- repaint();
-
- /* âXâîâbâhé≡ïxÄ~é╖éΘ */
- try {
- Thread.sleep( speed );
- } catch ( InterruptedException e ) {
- break;
- }
- }
- }
-
- /*
- * ôdî⌡îfĪö┬é≡ò`ëµé╖éΘ
- */
- public void paint(Graphics g)
- {
- int width = 0; /* âCâüü[âWò¥ */
-
-
- /* âIâtâXâNâèü[âôé¬ null é╠ÅΩìçüAÅêù¥é╡é╚éó */
- if ( neonScrGraph == null ) return ;
-
- /* âXâNâìü[âïé¬âIâtâXâNâèü[âôé≡Æ┤éªé╜ÅΩìçüAì┼Åëé⌐éτò`ëµé╖éΘ */
- if ( neonPos >= neonWidth )
- {
- neonPos = neonPos - neonWidth;
- }
-
- /* âIâtâXâNâèü[âôé≡Ä└ëµû╩é╔ò`ëµé╖éΘ */
- g.drawImage( neonScrImage, -neonPos, 0, this );
-
- /* ò`ëµîπüAîçæ╣ù╠êµé¬é┼é½é╜ÅΩìçüAâIâtâXâNâèü[âôé╠ɵô¬òöò¬é≡ò`ëµé╖éΘ */
- if ( ( neonWidth - neonPos ) < size().width )
- {
- for ( width = neonWidth; width < size().width; width += neonWidth )
- {
- g.drawImage( neonScrImage, -neonPos + width, 0, this );
- }
- int x = size().width - ( width - neonPos );
- g.drawImage( neonScrImage, size().width - x, 0, this );
- }
-
- /* ăé╠âlâIâôèJÄnê╩Æué≡É▌ÆΦé╖éΘ */
- neonPos = neonPos + ( ( lightSize + lightBetw ) * scroll );
- }
- public void update( Graphics g )
- {
- paint( g );
- }
-
- /*
- * âXâîâbâhé≡èJÄné╖éΘüB
- */
- public void start()
- {
- /* âXâîâbâhé≡èJÄné╖éΘ */
- if ( engine == null )
- {
- engine = new Thread( this );
- engine.start();
- }
- }
-
- /*
- * âXâîâbâhé≡ÆΓÄ~é╖éΘüB
- */
- public void stop()
- {
- /* âXâîâbâhé≡ÆΓÄ~é╖éΘ */
- if ( engine != null ) engine.stop();
- engine = null;
- }
-
- /*
- * â}âEâXé≡âNâèâbâNé│éΩé╜ÅΩìçé╔âXâîâbâhé≡Ä└ìsü^ïxÄ~é╖éΘ
- */
- public boolean mouseUp( Event evt, int x, int y )
- {
- /* Ä└ìsÆåé╠ÅΩìçé╔ïxÄ~é╖éΘ */
- if ( threadSuspended == false )
- {
- if ( engine != null ) engine.suspend();
- threadSuspended = true;
- }
- /* ïxÄ~Æåé╠ÅΩìçé╔Ä└ìsé╖éΘ */
- else
- {
- if ( engine != null ) engine.resume();
- threadSuspended = false;
- }
-
- return threadSuspended;
- }
- }
-