站内搜索: 请输入搜索关键词

当前页面: JAVA 编程资料牛鼻论坛Java & J2SE 技术区→请帮忙看看菜鸟问题~

请帮忙看看菜鸟问题~

发表新主题   回复此主题

第1楼 2008-03-18 18:10 lingling00happy 写道:

请帮忙看看菜鸟问题~

如果用户输入了错误ssn,对话框中出现“ssn not found”的消息。用户输入了真确的ssn,但输入的密码不正确,对话框中会出现消息“password does not match ssn”。ssn和密码均正确时,主窗口显示用户名的姓名和成绩。

编译时不不会出现任何错误
可是我的这些功能就是实现不了
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DialogDemo extends JFrame implements ActionListener {
private String [][] student = {
{"Mary","111","111","A"},
{"David","222","222","B"},
{"Smith","333","333","C"},
};
private JTextField jtfssn;
private JPasswordField jpfpassword;
JTextField jtfname;
JTextField jtfgrade;
JButton bfind;
public static void main(String[] args) {
DialogDemo frame = new DialogDemo();
frame.pack();
frame.setVisible(true);
// TODO Auto-generated method stub


}

public DialogDemo(){
setTitle("Find The Score");
JPanel jpLabel = new JPanel();
jpLabel.add(new Label("Enter SSN:"));
jpLabel.add(new Label("Enter Password:"));
jpLabel.add(new Label("Name:"));
jpLabel.add(new Label("Grade:"));
jpLabel.setLayout(new GridLayout(4,1));
JPanel jpTextField = new JPanel();
jpTextField .setLayout(new GridLayout(4,1));
jpTextField .add(jtfssn = new JTextField(10));
jpTextField .add(jpfpassword = new JPasswordField(10));
jpTextField .add(jtfname = new JTextField(10));
jpTextField .add(jtfgrade = new JTextField(10));
//p.add(bfind = new JButton("Find Sorce"));
jtfname.setEditable(false);
jtfgrade.setEditable(false);

JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add(jpLabel,BorderLayout.WEST);
p1.add(jpTextField,BorderLayout.CENTER);

JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout(new FlowLayout().CENTER));
p2.add(bfind = new JButton("Find Sorce"));

getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1,BorderLayout.CENTER);
getContentPane().add(p2,BorderLayout.SOUTH);

bfind.addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e) {
int index = find(jtfssn.getText().trim(),new String(jpfpassword.getPassword()));
if(index == -1){
JOptionPane.showMessageDialog(this,
"SSN not found","For Your Information",JOptionPane.INFORMATION_MESSAGE);
}
else if (index == -2){
JOptionPane.showMessageDialog(this,
"Password does not match SSN","For Your Information", JOptionPane.INFORMATION_MESSAGE);
}
else
{
jtfname.setText(student[index][0]);
jtfgrade.setText(student[index][3]);
}
// TODO Auto-generated method stub

}

private int find(String ssn, String pw) {
for(int i = 0;i<student.length;i++){
if(student[i][1].equals(ssn)&& student[i][2].equals(pw));
return i;}

for(int i = 0;i<student.length;i++)
if(student[i][1].equals(ssn))
return -2;

// TODO Auto-generated method stub
return -1;



}

/**
* @param args
*/


}

第2楼 2013-08-31 12:44 Robot :

请帮忙看看菜鸟问题~ 相关


发表新主题   回复此主题