You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.5 KiB
99 lines
3.5 KiB
/* |
|
* To change this license header, choose License Headers in Project Properties. |
|
* To change this template file, choose Tools | Templates |
|
* and open the template in the editor. |
|
*/ |
|
package propertiesswing; |
|
|
|
import java.awt.BorderLayout; |
|
import java.awt.Container; |
|
import java.awt.Dimension; |
|
import java.awt.FlowLayout; |
|
import java.awt.GridBagConstraints; |
|
import java.awt.GridBagLayout; |
|
import java.awt.GridLayout; |
|
import java.util.List; |
|
import java.util.Set; |
|
import javax.swing.JButton; |
|
import javax.swing.JFrame; |
|
import javax.swing.JLabel; |
|
import javax.swing.JPanel; |
|
import javax.swing.JPasswordField; |
|
import javax.swing.JTextField; |
|
|
|
/** |
|
* |
|
* @author denis |
|
*/ |
|
public class AuthorizationFrame extends JFrame{ |
|
|
|
|
|
|
|
public AuthorizationFrame(){ |
|
init(); |
|
setTitle("Authorization"); |
|
setLocationRelativeTo(null); |
|
setSize(400, 250); |
|
//pack(); |
|
setResizable(false); |
|
|
|
setVisible(true); |
|
} |
|
|
|
private void init(){ |
|
// Создаём верхнюю метку "Autorization" и размещаем её в панели "northPanel" |
|
JPanel northPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 40, 20)); |
|
JLabel authLabel = new JLabel("Authorization"); |
|
northPanel.add(authLabel); |
|
|
|
GridBagLayout gridLayout = new GridBagLayout(); |
|
GridBagConstraints constraints = new GridBagConstraints(); |
|
JPanel centerPanel = new JPanel(gridLayout); |
|
JLabel usernameLabel = new JLabel("username"); |
|
JTextField usernameField = new JTextField(30); |
|
JLabel passwordLabel = new JLabel("password"); |
|
JPasswordField passwordField = new JPasswordField(30); |
|
constraints.gridx = 0; |
|
constraints.gridy = 0; |
|
centerPanel.add(usernameLabel, constraints); |
|
constraints.gridx = 1; |
|
constraints.gridy = 0; |
|
centerPanel.add(usernameField, constraints); |
|
constraints.gridx = 0; |
|
constraints.gridy = 1; |
|
centerPanel.add(passwordLabel, constraints); |
|
constraints.gridx = 1; |
|
constraints.gridy = 1; |
|
centerPanel.add(passwordField, constraints); |
|
|
|
//Создаём две кнопки "SingIn" и "Cancel" и размещаем их в панели "southPanel" |
|
JButton singinButton = new JButton("SingIn"); |
|
singinButton.addActionListener(e -> { |
|
Set<Person> persons = PersonStore.getPersonStore().getPersons(); |
|
persons.forEach(person -> { |
|
if(usernameField.getText().equals(person.getUsername()) && |
|
passwordField.getText().equals(person.getPassword())){ |
|
new MainFrame(); |
|
} |
|
}); |
|
}); |
|
JButton cancelButton = new JButton("Cancel"); |
|
cancelButton.addActionListener(e -> { |
|
System.exit(0); |
|
}); |
|
JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 40, 20)); |
|
southPanel.add(singinButton); |
|
southPanel.add(cancelButton); |
|
|
|
|
|
//Помещаем панели в главном контейнере |
|
getContentPane().setLayout(new BorderLayout()); |
|
getContentPane().add(northPanel, BorderLayout.NORTH); |
|
getContentPane().add(centerPanel, BorderLayout.CENTER); |
|
getContentPane().add(southPanel, BorderLayout.SOUTH); |
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE); |
|
} |
|
|
|
|
|
|
|
}
|
|
|