Question

In: Computer Science

1. Explain how two controls can be set up to share the same event handler. How...

1. Explain how two controls can be set up to share the same event handler. How can the event handler tell which control generated the event?

2. Which user action generates three separate mouse events? Which events? Why?

3. Compare and contrast event handlers and change listeners.

Hello, I would really appreciate it if these 3 questions could be explained to me. These are in reference to the JAVA programming language. Specifically the JAVA GUI. I greatly appreciate a clear and understandable explanation. I WILL NOT BE COPY AND PASTING YOUR ANSWERS. Instead, I want to learn so I can form it in my own words.

Solutions

Expert Solution

ANSWER:---

1)---

        Event:--

            Change in the state of an object is known as event i.e. event describes the change in state of source. the system produces (or "fires") a signal of some kind when an event occurs, and provides a mechanism by which an action can be automatically taken when the event occurs.

Event Handling:-----

Event Handling is the mechanism that controls the event and decides what should happen if an event occurs. This mechanism have the code which is known as event handler that is executed when an event occurs.

Java Uses the Delegation Event Model to handle the events. This model defines the standard mechanism to generate and handle the events.

            The java.awt.event package provides many event classes and Listener interfaces for event handling.

Delegation Event Model has the following key :--

  • Source -----The source is an object on which event occurs. Source is responsible for providing information of the occurred event to it's handler. Java provide as with classes for source object.
  • Listener ------ Listener is responsible for generating response to an event. It is also known as event handler. Listener waits until it receives an event. Once the event is received. the listener process the event an then returns.

Steps involved in event handling:----

The User clicks the button and the event is generated.

· Now the object of concerned event class is created automatically and information about the source and the event get populated with in same object.

· Event object is forwarded to the method of registered listener class.

· the method is now get executed and returns.

2)------

  • · A mouse event is represented by an object of type MouseEvent.
  • Mouse events can actually be generated by other input devices, such as a trackpad or touch screen;
  • Mouse events can be left-button down, left-button up, double-click, etc
  • It gives us the coordinates (x,y) for every mouse event. By using these coordinates, we can draw whatever we want. To get the list of all available events
  • Events from these devices are translated by the system into MouseEvents.
  • All of the classes related to mouse and key events, can be found in package javafx.scene.input.
  • As the user manipulates the mouse, several kinds of event are generated.

For example, clicking a mouse button generates three events, a "mouse pressed" event, a "mouse released" event, and a "mouse clicked/typed" event.

the general form of these methods are void KeyPressed(KeyEventke), void KeyReleased(KeyEvent ke),, void KeyTyped(KeyEvent ke)

Simply moving the mouse generates a sequence of events as the mouse cursor moves from point to point on the screen. To respond to mouse events on a component, you can register listeners with that component.

We could register separate listener for each kind of mouse event on a component c using instance methods such as c.setOnMousePressed(handler) and c.setOnMouseMoved(handler).

3) ----------

Change listener

Event handler

A listener watches for an event to be fired. For example, a KeyListener waits for KeyEvents, a MessageListener waits for messages to arrive on a queue and so on.

The handler is responsible for dealing with the event. Normally, listeners and handlers go hand-in-hand. For example, the KeyListener tells the ExitHandler that "the letter Q was pressed" and the handler performs logic such as cleaning up resources and exiting the application gracefully. Similary a ButtonClickListener would tell the same ExitHandler that the "Exit button was clicked". So, in this case you have two different events, two different listeners but a single handler.

A listener, listens for events which are data value objects which describe an event. When the event occurred and the order of events is often

important. Pressing key '0' followed by '1' is different to '1' and '0'.

A handler, handles a complex object e.g. a new Socket connection. The handler might process the object for any length of time. The time of object creation and order is not so important. A connection from client0 or client1 can happen in any order.

Listener is associated with Event Source (Ex: key board)

Handler is associated with an Event (Ex: keydown

EventHandler is introduced in the JavaFX for all the UI controls. The EventHandler is a way to distinguish observable events and the ui events.

Whereas the Listener is borrowed for Observables, such as properties.

A listener, listens for events which are data value objects which describe an event.

A handler, handles a complex object. It is responsible for dealing with the event

"listeners" at the more abstract UI level

(where you'll be implementing your application logic).

handlers" at the look-and-feel level (for handling low-level widget events)

,


Related Solutions

Can two individuals share exactly the same environment? Please briefly explain your answer. Based on what...
Can two individuals share exactly the same environment? Please briefly explain your answer. Based on what you know, which set of individuals below would most likely have the most closely shared environment. Please briefly explain your answer. a. Mother and Daughter b. One male friend and one female friend c. Two female friends d. Monzygotic twins
explain clearly 1) the set-up of the Job Search Model, 2) how it is possible in...
explain clearly 1) the set-up of the Job Search Model, 2) how it is possible in such a setting that firms make more profit than predicted in the perfectly competition model, and 3) how this model may explain the finding in wages paid to similarly productive workers differ across industries and firms is in line with the standard labour market model with perfect competition?
How can two different benefit functions reflect exactly the same preferences? Explain.
How can two different benefit functions reflect exactly the same preferences? Explain.
How variance in budgets can be used as tools of controls in an organization. Explain this...
How variance in budgets can be used as tools of controls in an organization. Explain this using illustrations.
A sinking fund can be set up in one of two ways. Discuss the advantages and...
A sinking fund can be set up in one of two ways. Discuss the advantages and disadvantages of each procedure from the viewpoint of both the firm and its bondholders.
How to set up project communication plan for a project? How can the following be addressed:...
How to set up project communication plan for a project? How can the following be addressed: The scope of the communication, the lines of communication, the content and format of reporting, types of communications, timing of the communications, resources, administration, and document control? How do you ensure that project meetings turn out to be successful and what do managers need to cover in the meetings in order to be successful? Project management leadership is defined as? When thinking about leadership...
Consider two different implementations of the same instruction set architecture. The instructions can be divided into...
Consider two different implementations of the same instruction set architecture. The instructions can be divided into four classes according to their CPI (classes A, B, C, and D). P1 with a clock rate of 2.5 GHz and CPIs of 1, 2, 3, and 3, and P2 with a clock rate of 3 GHz and CPIs of 2, 2, 2, and 2. Given a program with a dynamic instruction count of 1.0E6 instructions divided into classes as follows: 10% class A,...
There are many variations on the Knapsack problem. In this question, consider the same set up...
There are many variations on the Knapsack problem. In this question, consider the same set up as the 0-1 Knapsack problem except suppose there are as many copies of each item as you would like. Thus, if one of the items is small but very valuable, it is possible to put many exact duplicates of that item into the knapsack. To maximize the value of items in the knapsack, the thief may decide to put in as many of the...
Two trains, A and B, travel in the same direction on the same set of tracks....
Two trains, A and B, travel in the same direction on the same set of tracks. A starts at rest at position d, and B starts with velocity v0 at the origin. A accelerates with acceleration a, and B decelerates with acceleration –a. What is the maximum value of v0 (in terms of d and a) for which the trains don’t collide? Make a rough sketch of x vs. t for both trains in the case where they barely collide.
1. List some controls that reduce fraud risks. 2. Explain how you can detect fraud
  1. List some controls that reduce fraud risks. 2. Explain how you can detect fraud.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT