Discuss any five event classes in java.

Every time a user interacts with a component on the GUI, events are generated. Events are objects that store information like the type of event that occurred, the source of the event, etc. Once the event is generated, then the event is passed to other objects, which handle or react to the event, called event listeners. Some event classes that represent the event and their corresponding listeners are:


Five of the many important event classes are:

(1) ActionEvent: 

In Java, most components have a special event called an ActionEvent. This is loosely speaking the most common or canonical event for that component. A good example is a click for a button. To have any component listen for an ActionEvent, we must register the

component with an ActionListener as:

component.addActionListener(new MyActionListener());

and then write the

public void actionPerformed(ActionEvent e);

method for the component to react to the event.


(2) ItemEvent: 

It is generated in case of JRadioButton, JCheckBox, JCheckBoxMenuItem, JComboBox and JList components. To have any component listen for an ItemEvent, we must register the component with an ItemListener as:

component.addItemListener(new MyItemListener);

and then write the

public void itemStateChanged(ItemEvent e);

method for the component to react to the event.


(3) MouseEvent:

It is generated in case of mouse clicks and mouse motion when the cursor is over Swing components such as JFrame. To have any component listen for a MouseEvent, we must register the component with either MouseListener or MouseMotionListener as:

component.addMouseListener(new MyMouseListener);

OR

component.addMouseMotionListener(new MyMouseMotionListener);

and then write the

public void mouseDragged(MouseEvent e);

public void mouseMoved(MouseEvent e);


OR

public void mouseClicked(MouseEvent e);

public void mousePressed(MouseEvent e);

public void mouseReleased(MouseEvent e);

public void mouseEntered(MouseEvent e);

public void mouseExited(MouseEvent e);

methods for the component to react to the event.


(4) KeyEvent:

It is generated in case of key presses and key depresses on text fields such as JTextField and JTextArea. One example of KeyEvent is user typing in a textfield. To have any component listen for a KeyEvent, we must register the component with KeyListener as:

component.addKeyListener(new MyKeyListener);

and then write the

public void keyPressed(KeyEvent e);

public void keyTyped(KeyEvent e);

public void keyReleased(KeyEvent e);

methods for the component to react to the event.


(5) WindowEvent:

It is generated in case of Swing window and its derivative components such as JFileDialog and JFrame. One example of WindowEvent is user closing a frame. To have any component listen for a WindowEvent, we must register the component with WindowListener as:

component.addWindowListener(new MyWindowListener);

and then write the

public void windowOpened(WindowEvent e);

public void windowClosing(WindowEvent e);

public void windowClosed(WindowEvent e);

public void windowIconified(WindowEvent e);

public void windowDeiconified(WindowEvent e);

public void windowActivated(WindowEvent e);

public void windowDeactivated(WindowEvent e);

methods for the component to react to the event.


However, we also do have the option to use corresponding Adapter classes instead of these Listener interfaces by which we can implement only the methods that are needed for the component and not define all the methods that are not necessary.



Comments

Popular posts from this blog

Suppose that a data warehouse for Big-University consists of the following four dimensions: student, course, semester, and instructor, and two measures count and avg_grade. When at the lowest conceptual level (e.g., for a given student, course, semester, and instructor combination), the avg_grade measure stores the actual course grade of the student. At higher conceptual levels, avg_grade stores the average grade for the given combination. a) Draw a snowflake schema diagram for the data warehouse. b) Starting with the base cuboid [student, course, semester, instructor], what specific OLAP operations (e.g., roll-up from semester to year) should one perform in order to list the average grade of CS courses for each BigUniversity student. c) If each dimension has five levels (including all), such as “student < major < status < university < all”, how many cuboids will this cube contain (including the base and apex cuboids)?

Suppose that a data warehouse consists of the four dimensions; date, spectator, location, and game, and the two measures, count and charge, where charge is the fee that a spectator pays when watching a game on a given date. Spectators may be students, adults, or seniors, with each category having its own charge rate. a) Draw a star schema diagram for the data b) Starting with the base cuboid [date; spectator; location; game], what specific OLAP operations should perform in order to list the total charge paid by student spectators at GM Place in 2004?

Explain network topology .Explain tis types with its advantages and disadvantges.