Home  >  Article  >  Java  >  What are the steps of java event processing

What are the steps of java event processing

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-12-27 16:14:586709browse

What are the steps of java event processing

What is an event?

An operation performed by a user on a component is called an event.

Event source: GUI component object that can generate events.

Event processing method: A method that can accept, parse and process event objects and implement interactive functions with users.

Event listener: a class that can handle events.

Steps in processing events:

Assume the event is XXXX

1. Register an event listener object for a certain event with the event source.

addXXXXListener(...);

2. Design an event listener that can handle this kind of event.

class 类名 implements XXXXListener{
重写XXXXListener接口中的方法
}

Note:

If you want to design a listener that can handle XXXX events, you only need to write a class that implements the XXXXListener interface, because in the XXXXListener interface Methods that can handle XXXX events have been defined.

eg:

import java.awt.*;
import java.awt.event.*;
class A implements ActionListener{
public void actionPerformed(ActionEvent e){//单击事件
System.out.println("haha");
}
}
public class text{
public static void main(String[] args){
Frame f=new Frame();
Button bn=new Button("ok");
f.add(bn);
A aa =new A();
bn.addActionListener(aa);
f.pack();//只显示内容高度和宽度
f.setVisible(true);
 }
}

What are the events:

ActionEvent: An event that occurs when a component is activated.

KeyEvent: Event that occurs when operating the keyboard.

MouseEvent: Occurs when the mouse is operated.

WindowsEvent: Event that occurs when operating a window.

PHP Chinese website has a large number of free JAVA introductory tutorials, everyone is welcome to learn!

The above is the detailed content of What are the steps of java event processing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is java sdkNext article:What is java sdk