Untitled
unknown
plain_text
a year ago
1.7 kB
15
Indexable
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Practical1 extends Applet implements ActionListener {
Label user, pass, message;
TextField userText, passText;
Button loginButton;
public void init() {
// Initialize components
user = new Label("Username:");
pass= new Label("Password:");
message= new Label();
userText = new TextField(20);
passText = new TextField(20);
passText.setEchoChar('*'); // To hide the password input
loginButton = new Button("Login");
// Set layout
setLayout(null);
// Position components
user.setBounds(50, 50, 80, 30);
userText.setBounds(150, 50, 150, 30);
pass.setBounds(50, 100, 80, 30);
passText.setBounds(150, 100, 150, 30);
loginButton.setBounds(150, 150, 80, 30);
message.setBounds(50, 200, 250, 30);
// Add components to the container window
add(user);
add(userText);
add(pass);
add(passText);
add(loginButton);
add(message);
// Add action listener
loginButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String username = userText.getText();
String password = passText.getText();
// validation for the username and password
if (username.equals("admin") && password.equals("password")) {
message.setText("Login successful!");
} else {
message.setText("Invalid username or password.");
}
}
}
Editor is loading...
Leave a Comment