반응형

스윙으로 GUI를 만들어 리스너에 코딩을 하고 했는데 코딩상에서 해당 컴포넌트에 걸린 이벤트를

실행하려고 별짓을 다 했다. ㅡㅡ; 그냥 이벤트 내에 들어가는 코딩을 메소드로 만들어 메소드를 호출하기도..

이건 아니다 싶어 이벤트 생성하여 해당 리스너를 참조하여 

 testListener.actionPerformed(new ActionEvent(jBtntest,ActionEvent.ACTION_PERFORMED, "openEvent"));

이렇게 해서 사용했다.. 대충 이렇게 하는게 낫나 싶어서 .. 므튼 이리저리 찾다보니 관련 자료를 찾았다.
 

원문: http://mindprod.com/jgloss/event11.html#SYNTHETICEVENTS

참조: http://www.codeguru.com/java/articles/162.shtml

JButton은 보통 doClick() 메소드를 이용하여 처리하면 되지만 다른 방법도 있으니 알아보자.

내가 주로 사용했던 방법은 2번 이었음..^^; 뭐 편법은 아닌듯.. ㅋㅋ

원문에서 필요한 부분만 발췌 하였음..

There are a number of ways to fake an event.

2) The simplest is just to call a Listener method directly with a dummy Event object, filled in with just enough data to keep the method happy.

3)Create an Event and introduce it to the Component that will handle it at the processEvent method. with:

 4)Create an Event 

 

 5)Generating MouseMoved Events has no effect on the screen mouse cursor. To make the underlying native GUI see your generated Events, use the Robot class to generate move clicks, moves etc. 

기본적으로 버튼에 따른 이벤트를 실행한다면 doClick()을 사용해야겠다.
그리고 일단 막히면 API 부터 제대로 뒤져봐야겠다 ㅡㅡ; 끙.. doClick 모르고 있었다는 ㅡㅡ;

2010.11.03  추가
오랫만에 기존에 작성했던 프로그램에 간단한 수정을 하면서 이벤트를 강제로 발생하는 부분을 검색

내가 기존에 포스팅 했던 글이 뜬다. ㅡㅡ;  예전에 몰라서 포스팅한걸 지금도 까먹다니 ㅠㅠ

그래서 조금 내용을 추가하여 갱신하기로 했다. 다시한번 잘 정리한다는 생각으로..^^

 

+ Recent posts