Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 ATM Machine Help...
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rawrawraw




PostPosted: Fri Jan 08, 2010 3:04 pm   Post subject: ATM Machine Help...

So I'm making an ATM Machine using GUI and I have a pin entry interface in the beginning where you press the puttons to enter your pin. I'm having trouble with comparing the pin entered in the JPasswordField to pins that are stored in a text file called pindatabase.txt. I'm using BufferedReader but it keeps saying File cannot be found even though I put it in a public void.

Here's my code so far:

code:
import javax.swing.*;
   import java.awt.*;
   import java.awt.event.*;
   
    public class pinentry extends JFrame implements ActionListener {
   
      JFrame frame = new JFrame("Pin Entry");
      JPanel pane = (JPanel) frame.getContentPane();
      JLabel p1 = new JLabel("Enter Your PIN: ");
      static final JPasswordField textField = new JPasswordField(15);
       
       public pinentry() {
     
     
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         pane.add(p1); 
           
         textField.setEchoChar('*');
         pane.add(textField);
       
         pane.setLayout(new FlowLayout());
         pane.setBorder(BorderFactory.createEmptyBorder(150,10,10,10));
       
         JButton b1 = new JButton ("1");
         b1.setActionCommand("1");
         b1.addActionListener(this);
         JButton b2 = new JButton ("2");
         b2.setActionCommand("2");
         b2.addActionListener(this);
         JButton b3 = new JButton ("3");
         b3.setActionCommand("3");
         b3.addActionListener(this);
         JButton b4 = new JButton ("4");
         b4.setActionCommand("4");
         b4.addActionListener(this);
         JButton b5 = new JButton ("5");
         b5.setActionCommand("5");
         b5.addActionListener(this);
         JButton b6 = new JButton ("6");
         b6.setActionCommand("6");
         b6.addActionListener(this);
         JButton b7 = new JButton ("7");
         b7.setActionCommand("7");
         b7.addActionListener(this);
         JButton b8 = new JButton ("8");
         b8.setActionCommand("8");
         b8.addActionListener(this);
         JButton b9 = new JButton ("9");
         b9.setActionCommand("9");
         b9.addActionListener(this);
         JButton b10 = new JButton ("0");
         b10.setActionCommand("0");
         b10.addActionListener(this);
         JButton b11 = new JButton ("Clear");
         b11.setActionCommand("Clear");
         b11.addActionListener(this);
         JButton b12 = new JButton ("Enter");
         b12.setActionCommand("Enter");
         b12.addActionListener(new pinCheck());
       
         pane.add(b1);
         pane.add(b2);
         pane.add(b3);
         pane.add(b4);
         pane.add(b5);
         pane.add(b6);
         pane.add(b7);
         pane.add(b8);
         pane.add(b9);
         pane.add(b10);
         pane.add(b11);
         pane.add(b12);
       
       
     
         frame.setContentPane(pane);
         frame.pack();
         frame.setSize(200,450);
         frame.setVisible(true);
      }
        
         
       public void actionPerformed(ActionEvent e) {
         String buttonPressed = e.getActionCommand();
           
         if (buttonPressed.equals("1")) {
            textField.setText(textField.getText()+"1");
         }
         else if (buttonPressed.equals("2")) {
            textField.setText(textField.getText()+"2");
         }
         else if (buttonPressed.equals("3")) {
            textField.setText(textField.getText()+"3");
         }
         else if (buttonPressed.equals("4")) {
            textField.setText(textField.getText()+"4");
         }
         else if (buttonPressed.equals("5")) {
            textField.setText(textField.getText()+"5");
         }
         else if (buttonPressed.equals("6")) {
            textField.setText(textField.getText()+"6");
         }
         else if (buttonPressed.equals("7")) {
            textField.setText(textField.getText()+"7");
         }
         else if (buttonPressed.equals("8")) {
            textField.setText(textField.getText()+"8");
         }
         else if (buttonPressed.equals("9")) {
            textField.setText(textField.getText()+"9");
         }
         else if (buttonPressed.equals("0")) {
            textField.setText(textField.getText()+"0");
         }
         else if (buttonPressed.equals("Clear")) {
            textField.setText("");
                
         }
      }
       class pinCheck implements ActionListener {
     
          public void actionPerformed(ActionEvent e) {
         
            File pindatabase = new File("pindatabase.txt");
            BufferedReader pinCheck = new BufferedReader(new FileReader(pindatabase));
            try {
               int check = pindatabase.read();
               if (textField.getText().equals(check)) {
                  JOptionPane.showMessageDialog(frame, "Your Pin is correct!");
               }  }
                catch (FileNotFoundException e) {
                  JOptionPane.showMessageDialog(frame, "File could not be found");
}
         
         }
      }
        
        
        
       private static void runGUI() {
         JFrame.setDefaultLookAndFeelDecorated(true);
         pinentry something = new pinentry();
      }
     
       public static void main(String[]args) {
         javax.swing.SwingUtilities.invokeLater(
                new Runnable() {
                   public void run() {
                     runGUI();
                  }
               });
      }
   }


Any suggestions?
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: