Nico B
3 years ago
4 changed files with 105 additions and 2 deletions
-
3GameProject/src/base/GameLoop.java
-
2GameProject/src/log4j2.xml
-
39GameProject/src/ui/GameUIWithLogin.java
-
63GameProject/src/ui/LoginWindow.java
@ -0,0 +1,39 @@ |
|||
package ui; |
|||
|
|||
import java.awt.event.ActionEvent; |
|||
import java.util.*; |
|||
|
|||
import javax.swing.JMenuItem; |
|||
|
|||
import org.apache.logging.log4j.LogManager; |
|||
import org.apache.logging.log4j.Logger; |
|||
|
|||
|
|||
public class GameUIWithLogin extends GameUI { |
|||
|
|||
private static final Logger logger = LogManager.getLogger(GameUIWithLogin.class); |
|||
|
|||
protected JMenuItem loginItem; |
|||
|
|||
public GameUIWithLogin(int sizeX, int sizeY) { |
|||
super(sizeX, sizeY); |
|||
logger.info("Hello Test"); |
|||
this.loginItem = new JMenuItem("Login ..."); |
|||
this.gameMenu.add(loginItem, 0); |
|||
this.loginItem.addActionListener(this); |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void actionPerformed(ActionEvent ae) { |
|||
super.actionPerformed(ae); |
|||
|
|||
if (ae.getSource() == this.loginItem) { |
|||
LoginWindow window = new LoginWindow(250, 300); |
|||
window.show(); |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,63 @@ |
|||
package ui; |
|||
|
|||
import java.awt.event.ActionEvent; |
|||
import java.awt.event.ActionListener; |
|||
|
|||
import javax.swing.*; |
|||
|
|||
public class LoginWindow implements ActionListener{ |
|||
protected JFrame frame; |
|||
protected JPanel panel; |
|||
|
|||
|
|||
protected JLabel loginLabel; |
|||
protected JTextField loginText; |
|||
protected JLabel passwordlabel; |
|||
protected JTextField passwordText; |
|||
protected JButton loginButton; |
|||
protected JOptionPane loginSuccess; |
|||
protected JOptionPane loginFailed; |
|||
|
|||
|
|||
|
|||
public LoginWindow(int sizeX, int sizeY) { |
|||
this.frame = new JFrame("Login"); |
|||
this.frame.setSize(sizeX, sizeY); |
|||
this.panel = new JPanel(); |
|||
this.frame.add(panel); |
|||
this.panel.setLayout(new BoxLayout(this.panel, BoxLayout.Y_AXIS)); |
|||
this.loginLabel = new JLabel("Login:"); |
|||
this.loginText = new JTextField(); |
|||
this.passwordlabel = new JLabel("Password:"); |
|||
this.passwordText = new JTextField(); |
|||
this.loginButton = new JButton("Login"); |
|||
this.loginButton.addActionListener(this); |
|||
|
|||
|
|||
this.panel.add(loginLabel); |
|||
this.panel.add(loginText); |
|||
this.panel.add(passwordlabel); |
|||
this.panel.add(passwordText); |
|||
this.panel.add(loginButton); |
|||
} |
|||
|
|||
public void actionPerformed (ActionEvent ae) { |
|||
|
|||
if(ae.getSource() == this.loginButton) { |
|||
if (loginText.getText().equals("admin") && passwordText.getText().equals("Password123!")) { |
|||
JOptionPane.showMessageDialog(frame, "Login erfolgreich", "Login Meldung", JOptionPane.INFORMATION_MESSAGE); |
|||
frame.setVisible(false); |
|||
|
|||
} else { |
|||
JOptionPane.showMessageDialog(frame, "Login fehlgeschlagen", "Login Meldung", JOptionPane.ERROR_MESSAGE); |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
public void show() { |
|||
frame.setVisible(true); |
|||
|
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue