Advertisement
Guest User

Untitled

a guest
May 15th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package com.example;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.WindowEvent;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9.  
  10.     public static void main(String[] args) throws Exception {
  11.         new Main().execute();
  12.     }
  13.  
  14.     private void execute() throws Exception {
  15.         Scanner scanner = new Scanner(System.in);
  16.  
  17.         System.out.println("Enter username:");
  18.         final String username = scanner.nextLine();
  19.  
  20.  
  21.  
  22.         final JFrame frame = new JFrame("Password");
  23.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24.  
  25.         Box layout = Box.createVerticalBox();
  26.  
  27.         JPasswordField password = new JPasswordField(30);
  28.         Button submit = new Button("Submit");
  29.         submit.addActionListener(actionEvent -> {
  30.             final String pass = new String(password.getPassword());
  31.  
  32.             System.out.println("Logging in with...");
  33.             System.out.println("Username: " + username);
  34.             System.out.println("Password: " + pass);
  35.  
  36.             frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
  37.         });
  38.  
  39.         layout.add(password);
  40.         layout.add(submit);
  41.  
  42.         frame.add(layout);
  43.         frame.setLocationRelativeTo(null);
  44.         frame.setSize(300, 120);
  45.         frame.pack();
  46.         frame.setVisible(true);
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement