[자바 질문] 변수값이 안바뀌는 ㅡㅡ;
참이삭
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 을 다시 만드신다던지
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2701151 | 사이트작업시 inputbox 가 readonly 형태표시 어떻게 하시나요? (1) | 찬내 | 2025-07-11 |
2701123 | 간단한 select 질문입니다 (3) | 천사의눈물 | 2025-07-11 |
2701061 | 비베질문.. | 똘끼 | 2025-07-10 |
2701034 | 메일폼 내 script 삽입가능한 방법 없을까요.. (2) | 마음새 | 2025-07-10 |
2701008 | 분명히 버튼을 만들었는데 액션이 안걸립니다. (3) | 재찬 | 2025-07-10 |
2700923 | 전체중앙정렬&독타입&쿼크모드 ㅜㅠ (8) | 푸른들 | 2025-07-09 |
2700893 | 질문드리겠습니다. | 도도한 | 2025-07-09 |
2700793 | 무비클립에 마우스 오버시 랜덤으로 효과음 나기는 어떻게 ;; (1) | 바닐라 | 2025-07-08 |
2700741 | 웹전송? (2) | 연와인 | 2025-07-07 |
2700686 | 카테고리 호버시 세부카테고리 보이게하는 것, css로만 가능할까요?? (3) | 다힘 | 2025-07-07 |
2700658 | 메타태그 질문드립니다..ㅠㅠ;;; | 모해 | 2025-07-07 |
2700632 | 외부에서 이미지 파일을 불러와야 합니다. 도와주세요. (4) | 에일린 | 2025-07-06 |
2700579 | (air + as3) smtp 이용해서 첨부파일 포함해서 메일 보내기 | 물보라 | 2025-07-06 |
2700524 | 클릭시 밑에 메뉴 나오게 (4) | 새솔 | 2025-07-05 |
2700505 | activex를 비쥬얼6.0으로 만들었는데요 비스타 배포시에 안되서 질문드립니다 (3) | 참이 | 2025-07-05 |
2700452 | c언어에서... 자료형 구분.... (3) | 시내 | 2025-07-05 |
2700422 | 버전에 관해 질문 | 라온제나 | 2025-07-04 |
2700393 | mysql이 갑자기!!!!!!!!!!!!!!!에러가;; (2) | 소미 | 2025-07-04 |
2700359 | 3.0 ) SimpleButton 상태 강제 변경 (3) | 희선 | 2025-07-04 |
2700304 | ie8 전용핵 문의 (3) | 여자 | 2025-07-03 |