관리 메뉴

IT 컴퓨터공학 자료실

Event Handler에 대해 본문

etc.. 기타 카테고리 2/영어 번역 & 일본어 번역

Event Handler에 대해

윤맨1 2015. 7. 14. 22:20

A trivial event handler

간단한 이벤트 핸들러

 

Because the code for checking for events and the main loop do not depend on the application, many programming frameworks take care of their implementation and expect the user to provide only the code for the event handlers.

 

많은 프로그래밍 프레임워크들은 자신들이 만들어내는 코드를 관리한다. 그리고 사용자에게 이벤트 핸들러에 대한 코드를 준비한다. 왜나하면 이벤트와 메인루프를 체크하는 코드가 어플리케이션에 의존하지 않기 때문이다.

 

Exception handlers

예외 핸들러

 

In PL/1, even though a program itself may not be predominantly event driven, certain abnormal events such as a hardware error, overflow or "program checks" may occur that possibly prevent further processing. Exception handlers may be provided by "ON statements" in (unseen) callers to provide housekeeping routines to clean up afterwards before termination.

 

PL/1(프로그래밍 언어의 한 종류)에서는 비록 프로그램이 그자체로 대개 event-driven 되지 않지만, 하드웨어 오류나 오버플로우, “프로그램 체크같은 확실한 비정상적인 이벤트는 추가적인 프로세싱을 막는 것이 가능하다. 예외 핸들러는 “ON statement”(보이지는 않지만, 동작하고있다는 의미) 상태로 동작되어, 프로세싱 종료 전에 처리해버리는 housekeeping routines(처리 루틴이라고 해석)을 제공한다.

 

Creating event handlers

이벤트 핸들러 만들기

 

The first step in developing an event-driven program is to write a series of subroutines, or methods, called event-handler routines. These routines handle the events to which the main program will respond. For example, a single left-button mouse-click on a command button in a GUI program may trigger a routine that will open another window, save data to a database or exit the application. Many modern day programming environments provide the programmer with event templates, allowing the programmer to focus on writing the event code.

 

event-driven program을 만드는 첫 번째 단계는 서브루틴과, 메소드, 이벤트 핸들러 루틴의 목록을 작성하는 것이다. 이러한 루틴은 메인프로그램에서 반응할 이벤트들을 관리하는 루틴이다. 예를 들면, GUI에서 커맨트를 마우스 왼쪽 클릭하면 다른 창이 열리는 루틴이 작동될 것이다. 그리고 데이터는 데이터베이스에 저장되거나 어플리케이션은 종료될지도 모른다. 현대 프로그래밍 환경 대부분에서는 개발자에게 이벤트 템플릿이라는 것을 제공해서, 개발자가 이벤트 코드를 작성하는 것에 집중할 수 있게 한다.

 

The second step is to bind event handlers to events so that the correct function is called when the event takes place. Graphical editors combine the first two steps: double-click on a button, and the editor creates an (empty) event handler associated with the user clicking the button and opens a text window so you can edit the event handler.

 

두 번째 단계는 이벤트 핸들러를 이벤트에 연결하여, 이벤트가 발생했을 때, 이벤트가 올바른 기능을 하게 묶는 것이다. 그래픽 에디터는 처음 두 단계를 결합한다: 버튼을 더블클릭한다, 그리고 에디터는 유저가 클릭한 버튼과 관련된 이벤트 핸들러를 생성한다. 텍스트 윈도우가 열리고 사용자는 이벤트 핸들러를 작성할 수 있다.

 

The third step in developing an event-driven program is to write the main loop. This is a function that checks for the occurrence of events, and then calls the matching event handler to process it. Most event-driven programming environments already provide this main loop, so it need not be specifically provided by the application programmer. RPG, an early programming language from IBM, whose 1960s design concept was similar to event driven programming discussed above, provided a built-in main I/O loop (known as the "program cycle") where the calculations responded in accordance to 'indicators' (flags) that were set earlier in the cycle.

 

event-driven programming의 세 번째 단계는 메인 루프를 작성하는 것이다. 메인 루프는 이벤트의 발생을 체크하는 기능을 하며, 이벤트에 맞는 이벤트 핸들러를 진행한다. 대개 event-driven programming 환경에는 메인루프가 이미 제공되고, 그렇기 때문에 개발자가 그것을 구체화시키면 된다. IBM에서 개발한 초창기 프로그래밍 언어인 RPG60년대 event-driven programming과 유사한 사상으로서 논의되었고, "program cycle"이라는 I/O 메인루프를 제공했다. 이 메인루프는 사이클 안에서 'indicators' (flags)라는 요소를 사용하여 프로그래밍을 쉽게 만들었다.



출처 : https://en.wikipedia.org/wiki/Event-driven_programming#Event_handlers