Java
Java
Here’s a short and precise version of answers and commented Java programs based on the
handwritten questions:
---
---
An Event Listener is an interface in Java used to handle events like button clicks. It contains methods
that get called when a specific event occurs.
---
---
import javax.swing.*;
import java.awt.event.*;
// Set bounds
nameLabel.setBounds(20, 20, 80, 25);
// Add Action
submitBtn.addActionListener(new ActionListener() {
JOptionPane.showMessageDialog(frame, info);
});
// Add components
frame.add(nameLabel); frame.add(nameField);
frame.add(emailLabel); frame.add(emailField);
frame.add(submitBtn);
frame.setSize(350, 200);
frame.setLayout(null);
frame.setVisible(true);
}
---
import javax.swing.*;
import java.awt.event.*;
button.addActionListener(new ActionListener() {
});
frame.add(button);
frame.setSize(300, 300);
frame.setLayout(null);
frame.setVisible(true);
---
Let me know if you want these saved as files or need help running them.