Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.WindowEvent;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) throws Exception {
- new Main().execute();
- }
- private void execute() throws Exception {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Enter username:");
- final String username = scanner.nextLine();
- final JFrame frame = new JFrame("Password");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Box layout = Box.createVerticalBox();
- JPasswordField password = new JPasswordField(30);
- Button submit = new Button("Submit");
- submit.addActionListener(actionEvent -> {
- final String pass = new String(password.getPassword());
- System.out.println("Logging in with...");
- System.out.println("Username: " + username);
- System.out.println("Password: " + pass);
- frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
- });
- layout.add(password);
- layout.add(submit);
- frame.add(layout);
- frame.setLocationRelativeTo(null);
- frame.setSize(300, 120);
- frame.pack();
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement