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.
104 lines
3.3 KiB
104 lines
3.3 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 propertiesswing2; |
|
|
|
import java.awt.Container; |
|
import java.awt.FlowLayout; |
|
import java.awt.GridBagConstraints; |
|
import java.awt.GridBagLayout; |
|
import java.awt.HeadlessException; |
|
import javax.swing.JButton; |
|
import javax.swing.JFrame; |
|
import javax.swing.JLabel; |
|
import javax.swing.JMenu; |
|
import javax.swing.JMenuBar; |
|
import javax.swing.JMenuItem; |
|
import javax.swing.JPanel; |
|
import javax.swing.JPasswordField; |
|
import javax.swing.JTextField; |
|
|
|
/** |
|
* |
|
* @author denis |
|
*/ |
|
public class AuthenticationFrame extends JFrame{ |
|
|
|
public AuthenticationFrame() { |
|
|
|
setTitle("Authentication"); |
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE); |
|
init(); |
|
setSize(500, 200); |
|
setResizable(false); |
|
setLocationRelativeTo(null); |
|
//pack(); |
|
setVisible(true); |
|
} |
|
|
|
private void init() { |
|
JMenuBar bar = new JMenuBar(); |
|
setJMenuBar(bar); |
|
JMenu menu = new JMenu("File"); |
|
bar.add(menu); |
|
JMenuItem openItem = new JMenuItem("Open"); |
|
JMenuItem closeItem = new JMenuItem("Close"); |
|
menu.add(openItem); |
|
menu.add(closeItem); |
|
closeItem.addActionListener(e -> { |
|
System.exit(0); |
|
}); |
|
|
|
|
|
|
|
GridBagLayout gbl = new GridBagLayout(); |
|
GridBagConstraints constraints = new GridBagConstraints(); |
|
Container container = getContentPane(); |
|
container.setLayout(gbl); |
|
|
|
|
|
constraints.gridx = 1; |
|
constraints.gridy = 0; |
|
JLabel authLabel = new JLabel("Authorization"); |
|
container.add(authLabel, constraints); |
|
|
|
JLabel usernameLanbel = new JLabel("username"); |
|
JTextField usernameText = new JTextField(30); |
|
constraints.gridx = 0; |
|
constraints.gridy = 1; |
|
container.add(usernameLanbel, constraints); |
|
constraints.gridx = 1; |
|
constraints.gridy = 1; |
|
container.add(usernameText, constraints); |
|
|
|
JLabel passwordLanbel = new JLabel("password"); |
|
JPasswordField passwordText = new JPasswordField(30); |
|
constraints.gridx = 0; |
|
constraints.gridy = 2; |
|
container.add(passwordLanbel, constraints); |
|
constraints.gridx = 1; |
|
constraints.gridy = 2; |
|
container.add(passwordText, constraints); |
|
|
|
JButton singIn = new JButton("SingIn"); |
|
JButton cancel = new JButton("Cancel"); |
|
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 30, 5)); |
|
constraints.gridx = 1; |
|
constraints.gridy = 3; |
|
container.add(panel, constraints); |
|
panel.add(singIn); |
|
panel.add(cancel); |
|
|
|
singIn.addActionListener(e -> { |
|
UserCheck check = new UserCheck(); |
|
if(check.check(usernameText.getText(), passwordText.getText())) System.out.println("Авторизация успешна"); |
|
else System.out.println("Имя пользователя или пароль не верны"); |
|
}); |
|
|
|
cancel.addActionListener(e -> { |
|
System.exit(0); |
|
}); |
|
} |
|
}
|
|
|