Events can be used for many purposes besides causing a method to run when a key
ID: 3875697 • Letter: E
Question
Events can be used for many purposes besides causing a method to run when a key is pressed in Alice, such as controlling burglar alarms, checking remote sensors, or checking for system events, like printers running out of paper.
Use one of these examples or come up with your own and describe how an event works in Alice 2.3?
How would an event trigger function in Alice 2.3 in your example?
How would the event function once the event trigger was initiated using an event handler in Alice 2.3?
Can you list, not describe, at least two other events similar to those above? In other words, can you come up with a unique example?
Explanation / Answer
First things first , we try to understand , "what is an event".
An "event" is nothing but occurrence of an action. The action could be anything in terms of a task or activity or day to day life activities. For example say birds chirping, clock ticking ,ringing of bells etc.
Similarly, when we are talking in terms of a computer system , an event could be any action that we perform on a computer like pressing of a key , clicking a mouse button, printer running out of paper etc.
Since event is an action and an action could have a wide range of values , it often becomes necessary to identify what sort of action has taken place. For this to happen we make use of a "Listener" , which is pre configured to identify a specific set of actions.
Once an event has been triggered , it expects a response for it. The response for the same is usually written in an "Event handler".
Alice is a tool that provides creating of event listeners and handlers. Let's take an example of "Checking the system events". As stated above , the system event could be any of the actions like pressing a key , clicking a mouse button , screen showing up something etc. For the sake of simplicity we would be taking the example of "Clicking a space bar".
As soon as you open Alice, the screen would appear with "Create new event" option.
1. Using this option you can create new events. For our example we would choose "When a key is pressed".
2. Now we can define our methods in the "methods" tab in the left bottom side of the screen by clicking "create new method". This basically acts as a event handler in our case. Let's say we want to print a message "Hello World".
3. We need to drag the created method into the "event tile" in order to activate the handler for suitable type of events.
As soon as you are done with this , and you set the program to run , a listener would be generated corresponding to "Step 1". This listener continuously polls for the specified set of action. Once the action has been performed, an "Event trigger" is generated and it finds a suitable handler for it (if defined already) , it executes the handler method which in our case is printing the message as "Hello World".
The two other events that we can describe would be -
1. Creating an alarm based on the system clock.
2. Developing a scheduler to run a specific application/task based on time or user generated event.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.