나는 스윙 타이머를 intervals.so에서 사용하는 간단한 응용 프로그램을 만들고 있습니다.하지만 100 밀리 초 간격으로 설정하면 문제가 발생합니다.왜 자바 스윙 타이머 자동 멈춤?
Timer t=new Timer(100, new ActionListener()//this is working
그러나 1000으로 설정하면 작동하지 않습니다.
Timer t=new Timer(1000, new ActionListener()//this is not working
오류없이하지만 낸것도 사용 netbeans.i이 .this을 중지 한 프로그램을 볼 수 없습니다 자동으로 terminate.timer 프로그램은 내가 콘솔에서 볼 것입니다.
내가 뭔가를 그리워 가지고 불러야 잘못 한 일을 내가 알아낼 수 없습니다?
이
은 타이머 스레드도 시작하기 전에 주 스레드가 종료되기 때문입니다 내 코드public class Screenshot {
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
private final String s;
int i=0;
public Screenshot() {
SimpleDateFormat sdf=new SimpleDateFormat("M,dd,hh,mm,ss");
s = sdf.format(new Date());
System.out.println(s);
shoot();
System.out.println("CALLED");
}
public final void shoot() {
Timer t=new Timer(1000, new ActionListener() {//not working with 1000 but work with 100
@Override
public void actionPerformed(ActionEvent e) {
try {
i++;
System.out.println(i);
BufferedImage capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, "jpg", new File("C:\\Users\\Madhawa.se\\Desktop\\screenshot\\"+s+"sh"+i+".jpg"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
t.start();
}
public static void main(String[] args) {
Screenshot shot=new Screenshot();
}
}
@getlost 정말 스레딩과 스윙 동시성에 대한 자습서를 읽어야합니다. 테스트 해보기위한 간단한 예제 프로그램을 작성할 때 어떤 일이 일어 났습니까? –