import java.awt.GridLayout;

創(chuàng)新互聯(lián)專注于舒城網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供舒城營銷型網(wǎng)站建設(shè),舒城網(wǎng)站制作、舒城網(wǎng)頁設(shè)計(jì)、舒城網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務(wù),打造舒城網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供舒城網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class LoginFrame extends JFrame {
private static final long serialVersionUID = 3536526127619569534L;
private JLabel nameLabel, passLabel;
private JTextField nameTextField;
private JPasswordField passwordField;
private JButton loginBtn;
public LoginFrame() {
// 設(shè)知彎置布局
this.setLayout(new GridLayout(3, 2));
nameLabel = new JLabel("用戶名:");
passLabel = new JLabel("密扒陸碼:");
nameTextField = new JTextField("請輸入用戶名");
passwordField = new JPasswordField();
loginBtn = new JButton("登錄");
loginBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// 驗(yàn)證是否成功的標(biāo)志
boolean isSafe = true;
try {
// 臨時(shí)變量
Integer tmp = Integer.valueOf(nameTextField.getText());
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "用戶名必須是數(shù)字");
isSafe = false;
}
try {
// 密碼的第一個(gè)字符
char start = passwordField.getPassword()[0];
if (!(start = 'a' start = 'z')
!(start = 'A' start = 'Z')) {
isSafe = false;
JOptionPane.showMessageDialog(null, "密碼必須以字母開頭");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "請輸入密碼");
isSafe = false;
}
if (isSafe) {
JOptionPane.showMessageDialog(null, "登錄搭此悶成功");
// 這里寫驗(yàn)證成功后要做的事
} else {
JOptionPane.showMessageDialog(null, "登錄失敗");
}
}
});
this.getContentPane().add(nameLabel);
this.getContentPane().add(nameTextField);
this.getContentPane().add(passLabel);
this.getContentPane().add(passwordField);
this.getContentPane().add(loginBtn);
this.setTitle("用戶登錄");
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
try {
UIManager.setLookAndFeel(lookAndFeel);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
LoginFrame login = new LoginFrame();
login.setVisible(true);
}
}
布局就用了比較簡單的GridLayout,如果要實(shí)現(xiàn)復(fù)雜的布局可以應(yīng)用多種布局加上GridBagLayout。主要看看合法性驗(yàn)證吧,方法肯定不止這一種的。
分享題目:java賬號檢驗(yàn)規(guī)格代碼 java登錄驗(yàn)證用戶名密碼是否正確
文章出自:http://chinadenli.net/article38/dspggsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、域名注冊、微信小程序、電子商務(wù)、自適應(yīng)網(wǎng)站、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)