Please list at least 3 events that we haven\'t discussed and associate them with
ID: 3557784 • Letter: P
Question
Please list at least 3 events that we haven't discussed and associate them with an listener and widget. Then pick one of these and write a simple code snippet, here's an example:
MouseEvent -> MenuListener -> JButton
JButton button = new JButton("Press Me"); // creates a GUI button widget
button.addMouseListener(new MouseListener() { // adds a mouse listener to the GUI button widget
public void mousePressed(MouseEvent mouseEvent) { // if the mouse button is pressed on the GUI button, do what is inside this method
button.setText("Button Pressed"); // change value of the GUI button from Press Me to Button Pressed
}
}
Explanation / Answer
Here is example with JToggleButton which add/remove MouseListener to JFrame.
examle with JButton: