Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Khan2ndSemAPL;
- import java.awt.Container;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import javax.swing.*;
- public class Activity_33_Reading_fromText_FileInputStream extends JFrame implements ActionListener
- {
- FileInputStream fsreader;
- public JLabel l1, l2;
- public JTextField t1, t2;
- public JButton b1, b2;
- Activity_33_Reading_fromText_FileInputStream()
- {
- Container c = getContentPane();
- c.setLayout(new GridLayout(3, 2));
- l1 = new JLabel("Customer Login Name: ");
- l2 = new JLabel("Password: ");
- t1 = new JTextField();
- t2 = new JPasswordField();
- b1 = new JButton("Login");
- b2 = new JButton("Clear");
- c.add(l1);
- c.add(l2);
- c.add(t1);
- c.add(t2);
- c.add(b1);
- c.add(b2);
- b1.addActionListener(this);
- b2.addActionListener(this);
- pack();
- setVisible(true);
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setLocationRelativeTo(null);
- }
- public void actionPerformed(ActionEvent ae)
- {
- if(ae.getSource() == b1)
- {
- if(t1.getText().isEmpty() || t1.getText().trim().equals("")
- || t2.getText().isEmpty() || t2.getText().trim().equals(""))
- {
- System.err.println("details are incomplete");
- JOptionPane.showMessageDialog(null, "Details are incomplete");
- }
- else
- {
- try
- {
- int i;
- char conv = Character.MIN_VALUE;
- //int file = Integer.MIN_VALUE;
- String user_pass = "";
- fsreader = new FileInputStream("C:\\Users\\10-0235C\\Documents\\migs\\login.text");
- String temp2 = "PASSWORD: " + t1.getText() + " USERNAME: " + t2.getText();
- //String temp2 = t1.getText() + t2.getText();
- System.out.println(" " + conv);
- System.out.println("password\\user inside text file: \nascii check if the same");
- while((i=fsreader.read())!= -1)
- {
- System.out.print(" " + i);
- System.out.print("=" + (char)i);
- conv = (char)i;
- // file = file + i;
- user_pass = user_pass + Character.toString(conv);
- }
- //System.out.println(file);
- System.out.println();
- System.out.println(user_pass);
- System.out.println();
- System.out.println("password\\user entered: \nascii check if the same");
- for(int loop = 0; loop < temp2.length(); loop++)
- {
- System.out.print(" " + (int)temp2.charAt(loop) + "=" + temp2.charAt(loop));
- }
- System.out.println();
- System.out.println(temp2);
- if(user_pass == temp2)
- //if(user_pass.equals(temp2))
- {
- System.out.println("\nmatch");
- JOptionPane.showMessageDialog(null, "match");
- }
- else
- {
- System.out.println("\nnot match");
- JOptionPane.showMessageDialog(null, "not match");
- }
- fsreader.close();
- }
- catch(FileNotFoundException e)
- {
- System.out.println("cannot find login.txt file " + e.toString());
- e.printStackTrace();
- }
- catch(IOException e)
- {
- System.out.println("Error writing to file " + e.toString());
- e.printStackTrace();
- }
- }
- }
- if(ae.getSource() == b2)
- {
- t1.setText(null);
- t2.setText(null);
- }
- }
- public static void main(String args[])
- {
- Activity_33_Reading_fromText_FileInputStream e = new Activity_33_Reading_fromText_FileInputStream();
- }
- }
Add Comment
Please, Sign In to add comment