1. 程式人生 > >自己做得簡單的登入框

自己做得簡單的登入框

package com.chinasoft.java.am;


import java.awt.BorderLayout;


public class denglu extends JFrame {


private JPanel contentPane;
private JPasswordField passwordField_1;
private JTextField textField;
private JLabel label;
private JLabel label_1;
private JRadioButton radioButton;
private JRadioButton radioButton_1;


/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
denglu frame = new denglu();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}


/**
* Create the frame.
*/
public denglu() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//登入整個頁面的大小布局
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setToolTipText("\u91CD\u7F6E");
contentPane.setBackground(new Color(51, 153, 204));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);

JButton btnNewButton = new JButton("\u767B\u5F55");//登入按鈕
btnNewButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {

if(passwordField_1.getText().equals("a7144772"))
{
new shouyin().setVisible(true);
}else
{
JOptionPane.showMessageDialog(null, "錯誤", "alert", JOptionPane.ERROR_MESSAGE);
}
//textField.getText();

}

});
btnNewButton.setBounds(278, 158, 70, 33);

JButton button = new JButton("\u91CD\u7F6E");//重置按鈕
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new denglu().setVisible(true);
}
});
button.setBounds(91, 158, 70, 33);

passwordField_1 = new JPasswordField();//密碼框
passwordField_1.setBounds(137, 99, 140, 21);//密碼框的大小
contentPane.setLayout(null);
contentPane.add(button);
contentPane.add(btnNewButton);
contentPane.add(passwordField_1);

textField = new JTextField();//登入名
textField.setText("售貨員");//登入框輸入的內容
textField.setBounds(137, 58, 140, 21);//登入名大小
contentPane.add(textField);
textField.setColumns(10);

label = new JLabel("\u767B\u5F55\uFF1A");//登入的字
label.setForeground(Color.ORANGE);
label.setFont(new Font("宋體", Font.PLAIN, 15));
label.setBounds(77, 52, 50, 33);
contentPane.add(label);

label_1 = new JLabel("\u5BC6\u7801\uFF1A");//密碼的字
label_1.setForeground(Color.ORANGE);
label_1.setFont(new Font("宋體", Font.PLAIN, 15));
label_1.setBounds(77, 93, 50, 33);
contentPane.add(label_1);

radioButton = new JRadioButton("\u8BB0\u4F4F\u8D26\u6237");
radioButton.setBounds(305, 57, 79, 23);
contentPane.add(radioButton);

radioButton_1 = new JRadioButton("\u8BB0\u4F4F\u5BC6\u7801");
radioButton_1.setBounds(305, 98, 79, 23);
contentPane.add(radioButton_1);
}
}