package me.teridax.jcash.gui.login; import javax.swing.*; import java.awt.*; public class LoginView extends JPanel { private final JTextField blz; private final JTextField iban; private final JPasswordField pin; private final JButton login; public LoginView() { this.blz = new JTextField("MA2424"); this.iban = new JTextField("4711"); this.pin = new JPasswordField("1234"); this.login = new JButton("Login"); setLayout(new BorderLayout(16, 16)); var content = new JPanel(); this.setBorder(BorderFactory.createEmptyBorder(8,8,8,8)); add(new JScrollPane(content), BorderLayout.CENTER); add(new JLabel("Bankautomat"), BorderLayout.NORTH); var layout = new GridBagLayout(); var constraints = new GridBagConstraints(); content.setLayout(layout); constraints.gridwidth = 4; constraints.insets = new Insets(12,12,12,12); addInputRow(constraints, content, blz, 1, "BLZ"); addInputRow(constraints, content, iban, 2, "Kontonummer"); addInputRow(constraints, content, pin, 3, "Passwort"); constraints.gridy = 4; constraints.anchor = GridBagConstraints.PAGE_END; constraints.weightx = 0; constraints.fill = GridBagConstraints.NONE; constraints.insets = new Insets(12,12,12,12); content.add(login, constraints); } private void addInputRow(GridBagConstraints constraints, JComponent target, JComponent comp, int row, String name) { constraints.gridwidth = 1; constraints.gridx = 1; constraints.gridy = row; constraints.weightx = 0; constraints.fill = GridBagConstraints.HORIZONTAL; target.add(new JLabel(name, SwingConstants.RIGHT), constraints); constraints.gridx = 2; constraints.gridy = row; constraints.weightx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; target.add(comp, constraints); } public JTextField getBlz() { return blz; } public JTextField getIban() { return iban; } public JPasswordField getPin() { return pin; } public JButton getLogin() { return login; } }