Advertisement
Guest User

Login

a guest
Apr 9th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.util.*;
  5.  
  6. public class Login extends JFrame{
  7.    
  8.     private JTextField user;
  9.     private JPasswordField pass;
  10.     private JButton ok;
  11.     private JButton cancel;
  12.     private String username;
  13.     private String password;
  14.     public Formatter x;
  15.    
  16.     public Login()
  17.     {
  18.        
  19.         super("Login");
  20.         setLayout(new FlowLayout());
  21.        
  22.         user = new JTextField(10);
  23.         add(user);
  24.        
  25.         pass = new JPasswordField(10);
  26.         add(pass);
  27.        
  28.         ok = new JButton("Ok");
  29.         add(ok);
  30.        
  31.         cancel = new JButton("Cancel");
  32.         add(cancel);
  33.        
  34.         thehandler handler = new thehandler(); //builds actionlistener object
  35.        
  36.         user.addActionListener(handler);
  37.         pass.addActionListener(handler);
  38.        
  39.         try{
  40.             x = new Formatter("logins.txt");
  41.         }
  42.         catch(Exception exception){
  43.             System.out.println("There has been a problem creating logins.txt");
  44.         }
  45.     }
  46.    
  47.     private class thehandler implements ActionListener
  48.     {
  49.         public void actionPerformed(ActionEvent event)
  50.         {
  51.             if(event.getSource() == ok)
  52.             {
  53.                 username = user.getText();
  54.                 password = user.getText();
  55.                 x.format("%s %s",username, password);
  56.             }
  57.            
  58.           /*else if(event.getSource() == cancel)
  59.             {
  60.                 Login.setVisible(false);  still figuring this out also.
  61.             } */
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement