Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- JavaScript
- 자바
- Docker Desktop
- class
- 스프링부트
- 배열
- event
- GIT
- array
- Swing
- 자바스크립트
- thread
- 객체
- SSL
- Python
- c#
- 클래스
- 메소드
- JS
- SpringBoot
- docker
- Dict
- StringBuilder
- 프로그래머스스쿨
- join()
- 저장소
- Java
- synchronized
- 파이썬
- AssertJ
Archives
- Today
- Total
정리노트
[자바/java] Thread 활용 이미지 이동 컨트롤 본문
package q3;
import java.awt.*;
import javax.swing.*;
public class Q3 extends JFrame {
class MyThread extends Thread {
private JLabel label;
int x, y;
MyThread(String file, int x, int y) {
this.x = x;
this.y = y;
label = new JLabel();
label.setIcon(new ImageIcon(file));
label.setBounds(x, y, 100, 100);
add(label);
}
public void run() {
while (x <= 400 || y <= 400) {
x += 10; y += 10;
label.setBounds(x, y, 100, 100);
repaint();
try {
Thread.sleep(10);
} catch (InterruptedException e) { }
}
}
}
Q3() {
setTitle("MoveStep");
setSize(500, 500);
setLayout(null);
new MyThread("---파일경로---", 0, 0).start();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
Q3 q = new Q3();
}
}
728x90
'프로그래밍 > Java' 카테고리의 다른 글
[자바/java] 하나의 list 두 개 스레드 동작 합 구하기 (0) | 2023.02.05 |
---|---|
[자바/java] Thread, Graphics 도형을 그리고 thread로 크기변화 (0) | 2023.02.05 |
[자바/java] thread 디지털 시계 (0) | 2023.02.04 |
[자바/java] thread 간 동작조정(생산자, 소비자) (0) | 2023.02.04 |
[자바/java] Thread 동기화 synchronized (0) | 2023.02.04 |