Âü°í]ScrollingText ¿¹Á¦


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :¾È±¤È£ 1999³â 3¿ù 13ÀÏ 11:09:08

In Reply to: µµ¿ÍÁÖ¼¼¿ä posted by B'baby on 1999³â 3¿ù 12ÀÏ 15:47:12:

ScrollingText¸¦ Áö¿øÇÏ´Â class¸¦ ¸¸µé¾î º¸¾Ò½À´Ï´Ù. ¾Æ·¡ÀÇ ¿¹Á¦¿¡¼­ ScrollingText¸¦ Applet¿¡ ½É¾î¼­ Å×½ºÆ®ÇØ º¸¾Ò½À´Ï´Ù. ¾ÆÁÖ ±âº»ÀûÀÎ ±â´É ¸î°¡Áö¸¸ ³Ö¾ú±â¶§¹®¿¡ ¿©±âÀÇ ¼Ò½º¸¦ ÀÌ¿ëÇÏ¿© Link¶óµç°¡, Multi Text Scroliing ±â´É µîÀÇ Á»´õ °í±ÞÀÇ ±â´ÉÀ» ³ÖÀ» ¼ö ÀÖ°ÚÁÒ.


ÀÔ¸À¿¡ ¸Â°Ô °íÃĺ¸¼¼¿ä.


/** ScrollingText class µ¥¸ð¿ë Applet ScrollingApplet.java
JDK 1.1.xÀÌ»óÀÇ È¯°æ¿¡¼­ ¹®Á¦¾øÀÌ ¼öÇàµË´Ï´Ù.
*/


import java.awt.*;
import java.applet.*;


public class ScrollingApplet extends Applet
{
ScrollingText text;
int inset = 5;


public void init()
{
setLayout(null);
setBackground(new java.awt.Color(0,128,0));


// ScrollingTextÀÇ ÀνºÅϽº¸¦ »ý¼ºÇÏ¿© Å©±â¸¦ ÁØ µÚ ScrollingApplet¿¡ Ãß°¡ÇÑ´Ù.
text = new ScrollingText();
add(text);


// »ý¼ºµÈ ScrollingText ÀνºÅϽºÀÇ °®Á¾ properities¸¦ ¼³Á¤ÇÑ´Ù.
// ÀÌ ºÎºÐÀº »ç¿ëÀÚ°¡ ¿øÇÏ´Â ÇüÅ·Π¼³Á¤ÇÑ´Ù.

String value;

value = getParameter("Inset");
if(value != null) inset = Integer.parseInt(value);

value = getParameter("Frame");
if(value != null) text.setFrame(value);

text.setForeground(Color.blue);
text.setBackground(Color.white);

value = getParameter("ScrollDirection");
if(value != null) text.setScrollDirection(Integer.parseInt(value));

value = getParameter("SrollUnit");
if(value != null) text.setScrollUnit(Integer.parseInt(value));

value = getParameter("SleepTime");
if(value != null) text.setSleepTime(Integer.parseInt(value));

value = getParameter("FontSize");
if(value != null){
Font font = getFont();
text.setFont(new Font(font.getName(), font.getStyle(), Integer.parseInt(value)));
}


// ScrollingText ÀνºÅϽº thread¸¦ °¡µ¿½ÃŲ´Ù.
Thread scrollThread = new Thread(text);
scrollThread.setPriority(Thread.MIN_PRIORITY);
scrollThread.start();


// ScrollingText instance sizing
Dimension dim;
dim = getSize();
text.setBounds(inset, inset, dim.width - inset*2, dim.height - inset*2);
}
}



/** ScrollingText class ScrollingText.java
ÀÌ ScrollText class´Â scroll text, font, ±ÛÀÚ»ö, ¹è°æ»ö
¹× scroll ¹æÇâ, scroll ´ÜÀ§, scroll ½Ã°£ °£°ÝÀ» ¼³Á¤ÇÒ ¼ö ÀÖ´Â ¿¹ÀÔ´Ï´Ù.


±âŸ Ãß°¡ÀûÀ¸·Î ÇÊ¿äÇÑ ±â´ÉÀº ¿©±â¿¡ ‰CºÙÀÌ¸é ´Ù¾çÇÑ È¿°ú¸¦ ¹ßÈÖÇÒ ¼öµµ ÀÖ°ÚÁÒ.
*/



import java.awt.*;


public class ScrollingText extends java.awt.Canvas implements Runnable
{
/** Constants */
public static final int SCROLL_LEFT = 0;
public static final int SCROLL_RIGHT = 1;

/** Properities */
protected int scrollDirection = SCROLL_LEFT;
protected int scrollUnit = 10;
protected int sleepTime = 200;
protected String frame = "Scrolling Text";

/** internal attributes */
transient protected int textX;
transient protected int textY;
transient protected int textWidth;
transient protected int textHeight;
transient protected Image textImage = null;


/** Properties setters & getters */

/** Scroll ¹æÇâ ¼³Á¤ method */
public void setScrollDirection(int d){
this.scrollDirection = d;
}

/** Scroll ´ÜÀ§(pixel) ¼³Á¤ */
public void setScrollUnit(int u){
this.scrollUnit = u;
}

/** ´ÜÀ§ Scroll°£ÀÇ °ø¹é½Ã°£(msec) ¼³Á¤ */
public void setSleepTime(int t){
this.sleepTime = t;
}

/** Scroll text ¼³Á¤ */
public void setFrame(String f){
this.frame = f;
}


/** super class method override */
public void paint(Graphics g){
Dimension dim = getSize();
if(isImageInvalid()){
textImage = createImage(dim.width, dim.height);
try{
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(textImage, 0);
tracker.waitForID(0);
}catch(InterruptedException e){}
}


Graphics textGC = textImage.getGraphics();


//Draw the background color
textGC.setColor(getBackground());
textGC.fillRect(0, 0, dim.width, dim.height);
textGC.setFont(getFont());


//Draw the text
textGC.setColor(getForeground());
textGC.drawString(frame, textX, textY);
g.drawImage(textImage, 0, 0, this);
if (textGC != null) textGC.dispose();
}


/** super class override method
È­¸é»óÀÇ ±ô¹ÚÀÓÀ» ÁÙÀ̱â À§ÇØ super classÀÇ method¸¦
overrideÇØ¾ß ÇÔ */
public void update(Graphics g) {
paint(g);
}


/** thread */
public void run(){
createTextParams();
while (true){
nextPos();
try{ Thread.sleep(sleepTime); }
catch(Exception e){ }
}
}


/** textX, textY, textWidth ÃʱⰪ ¼³Á¤ */
protected void createTextParams(){
Font f = getFont();
if (f != null){
FontMetrics fm = getFontMetrics(f);
textHeight = fm.getHeight();


Dimension dim = getSize();
textX = dim.width;
textY = ((dim.height - textHeight) >> 1) + fm.getAscent();
textWidth = fm.stringWidth(frame);
}
}


/** ´ÙÀ½ Ç¥½Ã À§Ä¡ °è»ê */
protected synchronized void nextPos(){
Dimension dim = getSize();
if (scrollDirection == SCROLL_LEFT){
textX -= scrollUnit;
if ((textX + textWidth) < 0) textX = dim.width;
}
else{
textX += scrollUnit;
if (textX > dim.width){
textX = -textWidth;
}
}


repaint();
}

/** textImage°¡ »ç¿ë°¡´É¿©ºÎ È®ÀÎ */
protected boolean isImageInvalid(){
Dimension s = getSize();
return (textImage == null ||
s.width != textImage.getWidth(this) ||
s.height != textImage.getHeight(this));
}
}






´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
HTML ÅÂ±× Æ÷ÇÔ ¿©ºÎ: HTML ¹®¼­ÀÏ °æ¿ì üũ
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]