-1
我的問題是,我想檢查電子郵件文本字段是否包含字符「@」。我該怎麼做呢?我也想檢查是否其他文本字段如名稱,用戶名,密碼是空的。提前感謝您的幫助。這個應用程序轟動了我的腦海!不能有效的電子郵件文本字段java
private JButton signupButton;
private JTextField name;
private JTextField email;
private JTextField username;
private JPasswordField pass;
private UserManager userManager;
public SignUpFrame (UserManager userManager){
super("Please fill in your Data");
userManager = new UserManager();
signupButton = new JButton("Sign Up!");
signupButton.addActionListener(new signupButtonListener());
name = new JTextField(15);
email = new JTextField(15);
username = new JTextField(15);
pass = new JPasswordField(15);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(5,2));
mainPanel.add(new JLabel("Name:"));
mainPanel.add(name);
mainPanel.add(new JLabel("Email:"));
mainPanel.add(email);
mainPanel.add(new JLabel("Username"));
mainPanel.add(username);
mainPanel.add(new JLabel("Password:"));
mainPanel.add(pass);
mainPanel.add(signupButton);
this.setContentPane(mainPanel);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
class signupButtonListener implements ActionListener{
public void actionPerformed(ActionEvent arg0) {
String nam,emai,id,psw;
nam = name.getText();
emai= email.getText();
id = username.getText();
psw = pass.getText();
User u1 = new User(nam,emai,id,psw);
UserManager.userList.add(u1);
}
通常在檢查長度之前,首先使用String.trim()方法。 – camickr