
네이버 메인에서 기사 헤드라인을 한줄씩 보여주는 원리
1. 큰 틀 작성: 스레드, main메소드
class NewsThread extends Thread{
public void run(){
}
}
public class Test{
public static void main(String[]args){
new NewsThread().start();
}
}
2.구현부 작성
class NewsThread extends Thread{
String[] news = {
"[이태원 참사] '그날 밤' 서울청 112상황실에선 무슨 일이",
"일본 수도권서 규모 5.0 지진…도쿄서도 진도3 흔들림",
"오늘부터 초겨울 추위…서울 아침 최저기온 '0도'",
"[속보] 한미 \“맞춤형 억제전략 개정 내년까지 완료 추진\”",
"다음 이메일, 한때 접속 오류 발생…\“20분만에 복구 완료\”"
}
public void run(){
int n = 0;
while(true){
System.out.println(news[n]);
if(n==news.length) n=0;
n++;
try{
Thread.sleep(1000);
}catch(InterruptedException ie){
System.out.println(ie.getMessage());
}
}
}
}
public class Test{
public static void main(String[]args){
new NewsThread().start();
}
}