package com.thread.sync;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import org.h2.constraint.Constraint;
public class ThreadGUI extends JFrame {
public ThreadGUI() {
setTitle("프로그래스바 - 스레드");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
JProgressBar bar = new JProgressBar(0, 100);
bar.setValue(30);
bar.setStringPainted(true);
bar.setForeground(Color.GREEN);
//bar.setBorderPainted(true);
//bar.setIndeterminate(true);
JButton btn = new JButton("버튼");
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Thread(new Runnable() {
@Override
public void run() {
synchronized (bar) {
for (int i=0; i<=100; i++) {
bar.setValue(i);
try {
Thread.sleep(20);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
} // run()
}).start();
}
});
contentPane.add(bar, BorderLayout.CENTER);
contentPane.add(btn, BorderLayout.SOUTH);
setLocationByPlatform(true);
setSize(400, 100);
setVisible(true);
}
public static void main(String[] args) {
new ThreadGUI();
}
}
'IT > Java' 카테고리의 다른 글
응용SW기초기술활용(윈도우 명령 프롬프트(DOS)용 명령어, 리눅스(유닉스) 콘솔 명령어) (0) | 2018.11.23 |
---|---|
java - 쓰레드를 적용한 채팅 소스(Thread Chatting) (0) | 2018.11.23 |
java - Thread 적용전 채팅 소스 (0) | 2018.11.22 |
java - Http 통신, URLConnection (0) | 2018.11.22 |
java - JFrame DB 연결 출력 (0) | 2018.11.22 |