프로그래밍/Java

Thread 예제 테스트

Jay Tech 2017. 1. 1. 17:09
반응형

import javax.swing.*;



public class test {


 public static void main(String[] args) throws Exception {

  

  Thread2 t2 = new Thread2();

  t2.start();

  String input = JOptionPane.showInputDialog("아무값이나쳐");

  System.out.println("입력하신 값은 : "+ input + "입니다");

 }

}


class Thread2 extends Thread{

 public void run(){

  for (int i = 10; i>0;  i--) {

   System.out.println(i);

   try{

    sleep(1000);

   }catch(Exception e){}

  }

 }

}




스레드를 생성하여 숫자가 줄어듦과 동시에 값을 입력해서 중간에 출력이 가능하다

반응형