Nico B 2 years ago
parent
commit
6849b69a9e
  1. 3
      GameProject/src/base/GameLoop.java
  2. 2
      GameProject/src/log4j2.xml
  3. 39
      GameProject/src/ui/GameUIWithLogin.java
  4. 63
      GameProject/src/ui/LoginWindow.java

3
GameProject/src/base/GameLoop.java

@ -10,6 +10,7 @@ import gameobjects.GameObject;
import playground.Level1;
import playground.Playground;
import ui.GameUI;
import ui.GameUIWithLogin;
/**
@ -86,7 +87,7 @@ public class GameLoop {
public void runGame(String[] args) throws IOException {
logger.info("GUI starts");
GameUI gameUI = new GameUI(SIZEX, SIZEY); // probably change to your new GUI class
GameUI gameUI = new GameUIWithLogin(SIZEX, SIZEY); // probably change to your new GUI class
double gameTime = -1;
Playground currentPlayground = null;

2
GameProject/src/log4j2.xml

@ -20,7 +20,7 @@
<appender-ref ref="File" />
</root>
<Logger name="playground.BreakoutLevel1" level="info">
<Logger name="ui.GameUIWithLogin" level="info">
</Logger>
</loggers>

39
GameProject/src/ui/GameUIWithLogin.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();
}
}
}

63
GameProject/src/ui/LoginWindow.java

@ -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);
}
}
Loading…
Cancel
Save