webnovel

Realizing a user login window by programming in the javax language

2024-09-19 02:54
[Requirements: (When the username is "admin" and the password is "123", the display is correct. Otherwise, the user does not exist.] I'm a beginner. I haven't made it up for a long time. Please help me, I'm very grateful!
2024-09-19 05:52

To program a user login window in the Java language, you can refer to the following sample code: ```java import javaawt*; import javaawtevent*; import javaxswing*; import javautil*; public class UserLoginWindow extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; private JPanel contentPane; private JTextField usernameField; private JTextField passwordField; private JButton registerButton; private JButton loginButton; private String username; private String password; private boolean register = false; private boolean login = false; public UserLoginWindow() { super(user login); contentPane = new JPanel(); contentPanesetLayout(new GridLayout(4 4)); usernameField = new JTextField(20); passwordField = new JTextField(20); registerButton = new JButton(register); loginButton = new Jbutton(login); contentPaneadd(username Field); contentPaneadd(passwordField); contentPaneadd(registerButtonbutton); contentPaneadd(loginButtonbutton); JPanel buttonPanel = new JPanel(); buttonPanelsetLayout(new BorderLayout(0 0)); add(contentPane BorderLayoutCENTER); add(buttonPanel BorderLayout BorderLayoutEAST); setSize(400 300); setDefaultCloseOperation(JFrameEXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e) { String username = usernameFieldgetText(); String password = passwordFieldgetText(); if (usernameequals(admin) && passwordequals(password)) { registerButtonsetEnabled(true); System outprint (login successful!); } else if (usernameequals(user) && passwordequals(123456)) { loginButtonsetEnabled(true); System out print in (User name or password error, please re-enter!); } else { System out print in (User name or password error!); } } public static void main(String[] args) { UserLoginWindow window = new UserLoginWindow(); } } ``` The user login window contains a text box for entering a username and password and two buttons for registering and logging in. When the user clicks the register button, the username and password text boxes will be cleared and the username and password entered will be checked to see if they match the username and password verified by the server. If it matches, the registration is successful. Otherwise, the user will be prompted to re-enter. When the user clicks the login button, the username and password text boxes will be cleared and the user name entered will be checked to see if it matches the username verified by the server. If it matches, the login is successful. Otherwise, the user will be prompted that the username or password is wrong.

a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z