*
Implementation function :

single click “ Sign in ” Button , If the user name and password are associated with the file 123.txt The user account information stored in is the same , Then pop up “ Validation passed !”, Otherwise, it is displayed “ Verification failed !”; single click “ Reset ” Button , Text box empty ; single click “ close ” Button , Exit the program .( Enter password to hide !)

*
Interface :

*
If the verification is passed :

*
If the verification fails :

*
Source code :
import java.io.*; import java.util.*; import java.awt.*; import
java.awt.event.*; import javax.swing.*; public class Test2 extends JFrame{
// The object of event listening should be set as global variable JTextField jtf; JTextField jta; public Test2() {
super(" User login window "); // label , Button JLabel lb0 = new JLabel(" User login window "); JLabel lb1 = new
JLabel(" user name :"); jtf = new JTextField(15); JLabel lb2 = new JLabel(" password :"); jta =
new JPasswordField(15); JButton b1 = new JButton(" Sign in "); JButton b2 = new
JButton(" Reset "); JButton b3 = new JButton(" close "); /// Monitoring event registration DataFind mm = new
DataFind(); b1.addActionListener(mm); // Reset button event b2.addActionListener( new
ActionListener(){ public void actionPerformed(ActionEvent ee){ jtf.setText("
"); jta.setText(" "); } }); // Close button event b3.addActionListener( new
ActionListener(){ public void actionPerformed(ActionEvent ee){ System.exit(0);
} }); // container , add to JPanel p = new JPanel(); p.add(lb0); p.add(lb1); p.add(jtf);
p.add(lb2); p.add(jta); p.add(b1); p.add(b2); p.add(b3);
getContentPane().add(p); setSize(500,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public
static void main(String[] args) { new Test2(); } // event listeners class DataFind
implements ActionListener{ public void actionPerformed(ActionEvent e) { String
str0 = jtf.getText(); String str1 = jta.getText(); boolean find = false; String
ss=""; try { Scanner sc = new Scanner(new File("123.txt"));
while(sc.hasNextLine()) { ss = sc.nextLine();
if(ss.indexOf(str0)>=0&&ss.indexOf(str1)>=0) { find = true; break; } } if(find)
{ String[] temp=ss.split("\\s+");
if(temp[0].equals(str0)&&temp[1].equals(str1)) {
JOptionPane.showMessageDialog(null," Validation passed !"); } } else
JOptionPane.showMessageDialog(null," Verification failed !"); } catch (Exception e2) { //
TODO: handle exception } } } }

Technology