Окно входа
Код: Выделить всё
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.*;
public class LoginWindow extends JFrame {
public LoginWindow() {
setTitle("Login Window");
setSize(800, 500);
setLocationRelativeTo(null);
setResizable(false);
setLayout(new GridBagLayout());
JLabel userLabel = new JLabel("Username:");
JTextField userField = new JTextField(15);
JLabel passLabel = new JLabel("Password:");
JPasswordField passField = new JPasswordField(15);
JButton loginButton = new JButton("Login");
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5);
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridx = 0; gbc.gridy = 0;
add(userLabel, gbc);
gbc.gridx = 1;
add(userField, gbc);
gbc.gridx = 0; gbc.gridy = 1;
add(passLabel, gbc);
gbc.gridx = 1;
add(passField, gbc);
gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = 2;
add(loginButton, gbc);
loginButton.addActionListener(e -> {
PasswordWindow window = new PasswordWindow();
window.setVisible(true);
SwingUtilities.getWindowAncestor(this).dispose();
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
Окно пароля
Код: Выделить всё
import javax.swing.*;
public class PasswordWindow extends JFrame {
private int width, height;
public PasswordWindow() {
width = 800;
height = 500;
setTitle("Password Manager");
setSize(width, height);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public void setWidth(int width){
this.width = width;
}
public void setHeight(int height){
this.height = height;
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... e-from-cli
Мобильная версия