[자바 질문] 변수값이 안바뀌는 ㅡㅡ;
참이삭
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LogoAnimator extends JLabel implements ActionListener {
String IMAGE_NAME = slimeY;
ImageIcon images[];
int totalImages = 6;
int currentImage = 0;
int animationDelay = 150;
int width;
int height;
String direction = L;
private Timer animationTimer;
public LogoAnimator()
{
images = new ImageIcon[ totalImages ];
for ( int count = 0; count images.length; ++count )
images[ count ] = new ImageIcon( getClass().getResource(
images/ + IMAGE_NAME + count + direction + .gif ) );
width = images[ 0 ].getIconWidth();
height = images[ 0 ].getIconHeight();
startAnimation();
}
public void paintComponent( Graphics g )
{
super.paintComponent( g );
images[ currentImage ].paintIcon( this, g, 0, 0 );
if ( animationTimer.isRunning() )
currentImage = ( currentImage + 1 ) % totalImages;
}
public void actionPerformed( ActionEvent actionEvent )
{
repaint();
}
public void startAnimation()
{
if ( animationTimer == null ) {
currentImage = 0;
animationTimer = new Timer( animationDelay, this );
animationTimer.start();
}
else
if ( ! animationTimer.isRunning() )
animationTimer.restart();
}
public void stopAnimation()
{
animationTimer.stop();
}
public Dimension getMinimumSize()
{
return getPreferredSize();
}
public Dimension getPreferredSize()
{
return new Dimension( width, height );
}
public void setImageName(String name)
{
IMAGE_NAME = name;
}
public void setDirection(String direc)
{
direction = direc;
}
} 위 클래스를 상속받은 다른 클래스에서
LogoAnimator logo = new LogoAnimator();
logo.setDirection(R); 이렇게 하면.. setDirection 안에서는 바뀌는데..
paintComponent( Graphics g ) 부분에 들어가면.. 다시 안바뀌고 L로 되어있습니다;
아무리해도 안바껴요.. 왜 그럴까요 -_-
-
헛소동
답글 감사하구요..
원래 움직이는 그림이 왼쪽을 보고 있는데 오른쪽 키 누르면 오른쪽을 보는거거든요;
그래서
for ( int count = 0; count images.length; ++count )
images[ count ] = new ImageIcon( getClass().getResource(
\images/\ + IMAGE_NAME + count + direction + \.gif\ ) );
이걸 setDirection(Strin -
미르
direction 의..L 과 R 이 무슨 관계인가요?
위에 보시면 \images/\ + IMAGE_NAME + count + direction + \.gif\ ) ); 이부분에서 direction 을 쓰는것 같은데요.
이미 저렇게 만들고 나면.. direction 의 값을 바꾼다 한들.... 이미 만들어진 ImgaeIcon 이 의미가 있을까 싶네요.. 한번 생각해보세요. direction 의 값을 바꾸고 나면. ImageIcon 을 다시 만드신다던지