Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.util.*;
- public class Login extends JFrame{
- private JTextField user;
- private JPasswordField pass;
- private JButton ok;
- private JButton cancel;
- private String username;
- private String password;
- public Formatter x;
- public Login()
- {
- super("Login");
- setLayout(new FlowLayout());
- user = new JTextField(10);
- add(user);
- pass = new JPasswordField(10);
- add(pass);
- ok = new JButton("Ok");
- add(ok);
- cancel = new JButton("Cancel");
- add(cancel);
- thehandler handler = new thehandler(); //builds actionlistener object
- user.addActionListener(handler);
- pass.addActionListener(handler);
- try{
- x = new Formatter("logins.txt");
- }
- catch(Exception exception){
- System.out.println("There has been a problem creating logins.txt");
- }
- }
- private class thehandler implements ActionListener
- {
- public void actionPerformed(ActionEvent event)
- {
- if(event.getSource() == ok)
- {
- username = user.getText();
- password = user.getText();
- x.format("%s %s",username, password);
- }
- /*else if(event.getSource() == cancel)
- {
- Login.setVisible(false); still figuring this out also.
- } */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement