Practical 12
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class SimpleLoginForm extends JFrame{
public SimpleLoginForm() {
// Create the frame
setTitle("Simple Login Form");
setSize(300, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// Create components
JLabel usernameLabel = new JLabel("Username:");
JTextField usernameField = new JTextField(15);
JLabel passwordLabel = new JLabel("Password:");
JPasswordField passwordField = new JPasswordField(15);
JButton loginButton = new JButton("Login");
// Set up the layout
setLayout(new GridLayout(3, 2));
// Add components to the frame
add(usernameLabel);
add(usernameField);
add(passwordLabel);
add(passwordField);
add(loginButton);
// Add ActionListener to the button
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = [Link]();
String password = new String([Link]());
[Link](null, "Username: " + username + "\nPassword: " +
password);
});
public static void main(String[] args) {
SimpleLoginForm form = new SimpleLoginForm();
[Link](true);
}
}
Output: