如何把密码改为从文件中获取进行对比
菜鸟,实在是不会,找了好多方法,就是调试错误,求大神赐一计,万分感谢,下面是我的代码(标注部分为现在的方法)package TestLog;
import Test.Logincd1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Login2 extends JFrame
{
private JPanel panel=new JPanel();
private JPanel panel1=new JPanel();
private JPanel panel2=new JPanel();
private JPanel panel3=new JPanel();
private JPanel panel4=new JPanel();
private JLabel l1=new JLabel("登录名");
private JLabel l2=new JLabel("密码");
private JLabel l3=new JLabel("考勤管理系统");
private JTextField f1=new JTextField(11);
private JTextField f2=new JTextField(11);
private JButton jbtBack=new JButton("重置");
private JButton jbtOK=new JButton("登录");
private JButton jbtCancel=new JButton("取消");
public Login2()
{
l3.setFont(new Font("TimesRoman",Font.BOLD,20));
l1.setForeground(new Color(70,130,180));
l2.setForeground(new Color(70,130,180));
l3.setForeground(new Color(70,130,180));
jbtBack.setForeground(new Color(70,130,180));
jbtOK.setForeground(new Color(70,130,180));
jbtCancel.setForeground(new Color(70,130,180));
setLayout(new BorderLayout(8,10));
add(panel1,BorderLayout.WEST);
add(panel2,BorderLayout.NORTH);
add(panel3,BorderLayout.CENTER);
add(panel4,BorderLayout.SOUTH);
panel1.add(l3);
panel2.add(l1);
panel2.add(f1);
panel3.add(l2);
panel3.add(f2);
panel4.add(jbtOK);
panel4.add(jbtBack);
panel4.add(jbtCancel);
panel.add(panel1);
panel.add(panel2);
panel.add(panel3);
panel.add(panel4);
add( panel);
panel.setOpaque(false);
panel1.setOpaque(false);
panel2.setOpaque(false);
panel3.setOpaque(false);
panel4.setOpaque(false);
jbtOK.addActionListener(new Enter());
jbtBack.addActionListener(new ReWrite() );
jbtCancel.addActionListener(new Close());
}
public static void main (String[] args)
{
Login2 frame=new Login2();
frame.setTitle("考勤管理系统");
frame.setSize(250,250);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
ImageIcon background = new ImageIcon("C:/Users/Administrator/workspace/Log/src/Test/picture/2.jpg");
JLabel label = new JLabel(background);
label.setBounds(0, 0, background.getIconWidth(),
background.getIconHeight());
JPanel imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
}
class Enter implements ActionListener{
public void actionPerformed(ActionEvent e)
{
if((f1.getText()).equals("abc")&&(f2.getText()).equals("123"))
{
JOptionPane.showMessageDialog( null,"登录成功,教师登录!");
Login2.this.setVisible(false);
TeacherLogin.TeacherSystem();
}
else if ((f1.getText()).equals("ABC") && (f2.getText()).equals("111")) {
JOptionPane.showMessageDialog(null, "登录成功,学生登录!");
Login2.this.setVisible(false);
StudentLogin.Checkin();
}
else JOptionPane.showMessageDialog(null, "用户名或密码错误,登录失败,请重新登录!");
}
}
class ReWrite implements ActionListener{
public void actionPerformed(ActionEvent e)
{
f1.setText("");
f2.setText("");
f1.requestFocus();
}
}
class Close implements ActionListener{
public void actionPerformed(ActionEvent e)
{
JButton bt=(JButton)e.getSource();
if(bt.equals(jbtCancel));
System.exit(0);
}
}
}