應用程序將要求用戶的ID和密碼,以及他們是現有的還是新的用戶,如何創建一個GUI java的密碼和ID。如果您是新用戶,則會提示您重新輸入您的詳細信息以確認ID和密碼,然後將它們存儲在陣列中。 一旦用戶點擊登錄按鈕,應用程序將搜索一系列ID和密碼進行驗證。 (將您的陣列設置爲包含最多10個用戶 - 因爲它是一個小陣列可以使用線性搜索) 然後應用程序將顯示適當的消息。如何使用陣列
到目前爲止我的代碼
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Log extends JFrame
{
public static void main(String[] args)
{
Log frameTabel = new Log();
}
JLabel title = new JLabel("Please type your ID and Password");
JLabel id = new JLabel("ID:");
JLabel psword = new JLabel("Password:");
JButton blogin = new JButton("Login");
JPanel panel = new JPanel();
JTextField txuser = new JTextField(15);
JPasswordField pass = new JPasswordField(15);
JRadioButton radNew = new JRadioButton("New", true);
JRadioButton radExisting = new JRadioButton("Existing", false);
ButtonGroup radioGroup1 = new ButtonGroup();
Log()
{
super("Week 9 Question 3");
setSize(300,250);
setLocation(600,250);
panel.setLayout (null);
title.setBounds(40,5,300,20);
id.setBounds(52,40,150,20);
txuser.setBounds(70,40,150,20);
psword.setBounds(7,80,150,20);
pass.setBounds(70,80,150,20);
blogin.setBounds(180,130,80,20);
radNew.setBounds(30, 130, 50, 20);
radExisting.setBounds(90, 130, 90, 20);
panel.add(title);
panel.add(id);
panel.add(psword);
panel.add(blogin);
panel.add(txuser);
panel.add(pass);
add(radNew);
add(radExisting);
radioGroup1.add(radNew);
radioGroup1.add(radExisting);
map.put("test", "12345");
getContentPane().add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
actionlogin();
}
public void actionlogin() {
blogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String puname = txuser.getText();
String ppaswd = new String(pass.getPassword());
JOptionPane.showMessageDialog(null, "Correct Information", "Correct",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "No Password/ID Found on System",
"Incorrect", JOptionPane.INFORMATION_MESSAGE);
txuser.setText("");
pass.setText("");
txuser.requestFocus();
if (radNew.isSelected()) {
}
JOptionPane.showMessageDialog(null,
"Re-enter your password and ID to confirm", "Information Saved",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
});
}
}
刪除'map.put( 「」, 「」);'。如果用戶沒有在ID和密碼中輸入任何值,仍會顯示正確的信息。 – Braj
什麼問題? – MadProgrammer