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.
64 lines
1.5 KiB
64 lines
1.5 KiB
package ui;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.event.*;
|
|
|
|
public class LoginWindow extends GameUIWithLogin implements ActionListener {
|
|
|
|
JFrame frame = null;
|
|
JPanel contentPane = null;
|
|
JTextField tf1 = null;
|
|
JTextField tf2 = null;
|
|
JLabel name = null;
|
|
JLabel password = null;
|
|
JButton login = null;
|
|
|
|
public LoginWindow(int sizeX, int sizeY) {
|
|
super(sizeX, sizeY);
|
|
|
|
this.frame = new JFrame("Login");
|
|
|
|
this.contentPane = new JPanel();
|
|
this.frame.setContentPane(this.contentPane);
|
|
|
|
this.tf1 = new JTextField("",20);
|
|
this.tf2 = new JTextField("",20);
|
|
|
|
this.name = new JLabel("Login: ");
|
|
this.password = new JLabel("Passwort: ");
|
|
|
|
this.contentPane.add(this.name);
|
|
this.contentPane.add(this.tf1);
|
|
this.contentPane.add(this.password);
|
|
this.contentPane.add(this.tf2);
|
|
|
|
this.login = new JButton("Login");
|
|
this.contentPane.add(this.login);
|
|
|
|
this.tf1.addActionListener(this);
|
|
this.tf2.addActionListener(this);
|
|
this.login.addActionListener(this);
|
|
|
|
this.frame.setSize(250, 200);
|
|
|
|
this.frame.setVisible(true);
|
|
|
|
|
|
|
|
}
|
|
@Override
|
|
public void actionPerformed(ActionEvent ae) {
|
|
if(ae.getSource() == this.login) {
|
|
|
|
if(tf1.getText().equals("user") && tf2.getText().equals("pw")) {
|
|
JOptionPane.showMessageDialog(contentPane, "Login successfully");
|
|
this.frame.dispose();
|
|
} else {
|
|
JOptionPane.showMessageDialog(contentPane, "Login failed - Try again", "Login failed", JOptionPane.ERROR_MESSAGE);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|