網站制作NEWS
eclipse 編寫JAVA程序 只想編寫一個界面,輸入賬號和密碼的,但是出錯,請高手幫忙分析錯誤 代碼如下
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test_Login extends javax.swing.JFrame {
private JPanel jPanel1;
private JButton bntLogin;
private JButton bntCannel;
private JPasswordField pwd;
private JTextField username;
private JLabel jLabel2;
private JLabel jLabel1;
public static void main(String[] args) {
Test_Login inst = new Test_Login();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
public Test_Login() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jPanel1 = new JPanel();
getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.setLayout(null);
{
jLabel1 = new JLabel();
jPanel1.add(jLabel1);
jLabel1.setText("用戶名");
jLabel1.setBounds(45, 30, 75, 25);
}
{
jLabel2 = new JLabel();
jPanel1.add(jLabel2);
jLabel2.setText("密碼");
jLabel2.setBounds(45, 75, 55, 15);
}
{
username = new JTextField();
jPanel1.add(username);
username.setBounds(100, 30, 140, 25);
}
{
pwd = new JPasswordField();
jPanel1.add(pwd);
pwd.setBounds(100, 70, 140, 25);
}
{
bntLogin = new JButton();
jPanel1.add(bntLogin);
bntLogin.setText("登陸");
bntLogin.setBounds(40, 120, 60, 30);
bntLogin.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (username.getText().equals("小王")
&& pwd.getText().equals("xiaowang")) {
JOptionPane.showMessageDialog(Test_Login.this,
"登錄成功");
} else {
JOptionPane.showMessageDialog(Test_Login.this,
"登錄失敗");
}
}
});
bntCannel = new JButton();
jPanel1.add(bntCannel);
bntCannel.setText("取消");
bntCannel.setBounds(180, 120, 60, 30);
bntCannel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
System.exit(0);
}
});
}
}
pack();
setSize(300, 215);
} catch (Exception e) {
e.printStackTrace();
}
}
}
試試這個代碼 用戶登錄界面的 輸入用戶名和密碼的
多重隨機標簽