Java Event Monitoring Mechanism Explanation
- 2021-06-28 12:41:18
- OfStack
Add listeners to components
Define a class that inherits ActionListener
pubulic class ButListener implements ActionListener{
Public void actionPerformed(ActionEvent e){
}}
Add an action listener method to a button
ButListener but = new ButListen();
jbu.addActionListener(but);
Add a monitoring mechanism and then create a window in the listener ButListener time processing method to get the window after clicking the button.
Relistener
Define an JTextField variable, jt, to hold the text st box object passed in
public JTextField jt;
public JTextField jt2;
public void actionPerformed(ActionEvent e) {
// Gets the string inside the text box
String name = jt.getText();
String mima = jt2.getText();
if ( " 123 " .equals(name)&& " 321 " .equals(mima)) { ... .
}else( ... ){ ... }
}
summary