Übungen
parent
4c82d7cbb4
commit
8b535d801d
|
@ -0,0 +1,37 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Bank {
|
||||
|
||||
private String bankname;
|
||||
private ArrayList<User> kunden;
|
||||
|
||||
public Bank(String bankname) {
|
||||
|
||||
this.bankname = bankname;
|
||||
this.kunden = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void kunde_Hinzufuegen(User kunde) {
|
||||
this.kunden.add(kunde);
|
||||
}
|
||||
|
||||
public ArrayList<User> getKunde_List(){
|
||||
return kunden;
|
||||
}
|
||||
|
||||
public String getKunde(int kundenummer) {
|
||||
for (User user: kunden) {
|
||||
if (user.getKundennummer() == kundenummer)
|
||||
return user.toString();
|
||||
}
|
||||
|
||||
|
||||
return "Kunde wurde nicht gefunden!";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,72 +1,81 @@
|
|||
package BankSystemGUI;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Base64;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
||||
public class Controller {
|
||||
private Window view;
|
||||
private Modell erstelleKonto;
|
||||
private UserDao userDao;
|
||||
private UserWindow userWindwo;
|
||||
private User user;
|
||||
private Konto konto;
|
||||
private Bank bank;
|
||||
private ViewLogin login_fuer_user;
|
||||
private HauptFenser userFenser;
|
||||
private EinzahlungsFenster einzahlungsfenster;
|
||||
|
||||
public Controller(Connection connection) throws SQLException {
|
||||
this.view = new Window();
|
||||
this.userDao = new UserDaoImpl(connection); // DAO-Implementierung wird hier verwendet
|
||||
public Controller(Konto konto, Bank bank, ViewLogin login_fuer_user, HauptFenser userFenser) {
|
||||
this.konto = konto;
|
||||
this.bank = bank;
|
||||
this.login_fuer_user = login_fuer_user;
|
||||
this.userFenser = userFenser;
|
||||
einzahlungsfenster = new EinzahlungsFenster();
|
||||
action_login();
|
||||
action_Einzahlen();
|
||||
Einzahlen();
|
||||
}
|
||||
|
||||
this.view.setAction(new ActionListener() {
|
||||
public void login() {
|
||||
String name = login_fuer_user.getName();
|
||||
String vorname = login_fuer_user.getVorname();
|
||||
user = new User(name,vorname);
|
||||
konto = new Konto(0,user);
|
||||
user.konto_Hinzufuegen(konto);
|
||||
login_fuer_user.schließe_login();
|
||||
userFenser.set_user_name(user.getName() + " " + user.getVorname());
|
||||
userFenser.set_user_kontostand(konto.getKontostand());
|
||||
userFenser.zeige_HauptFenster();
|
||||
}
|
||||
|
||||
public void zeige_fenster_einzahlen() {
|
||||
einzahlungsfenster.zeige_fenster();
|
||||
}
|
||||
|
||||
public void einazahlen() throws Exception {
|
||||
String betrag_text = einzahlungsfenster.getBetrag();
|
||||
double betrag =Double.parseDouble(betrag_text);
|
||||
konto.einzahlen(konto.getKontostand() +betrag);
|
||||
userFenser.set_user_kontostand(konto.getKontostand());
|
||||
einzahlungsfenster.setBetrag("");
|
||||
einzahlungsfenster.zeige_message("Einzalhung ist Erfolgreich");
|
||||
einzahlungsfenster.schließe_fenster();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// **************************************Buttons Actions**************************************
|
||||
public void action_login() {
|
||||
login_fuer_user.zeige_login();
|
||||
login_fuer_user.getLogin().addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
erstelleKonto();
|
||||
} catch (SQLException | NoSuchAlgorithmException e1) {
|
||||
e1.printStackTrace();
|
||||
login();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void action_Einzahlen() {
|
||||
userFenser.getEinzahlen().addActionListener(e -> zeige_fenster_einzahlen());
|
||||
}
|
||||
|
||||
public void Einzahlen() {
|
||||
einzahlungsfenster.getEinzahlen().addActionListener(e -> {
|
||||
try {
|
||||
einazahlen();
|
||||
} catch (Exception e1) {
|
||||
einzahlungsfenster.zeige_Error(e1.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void erstelleKonto() throws SQLException, NoSuchAlgorithmException {
|
||||
String email = view.textFieldEmail.getText();
|
||||
String name = view.textFieldName.getText();
|
||||
String vorname = view.textFieldVorname.getText();
|
||||
String password = view.textFieldPassword.getText();
|
||||
String teleN = view.textFieldTeleN.getText();
|
||||
String salt = createSalt();
|
||||
String hashedPassword = hashPassword(password, salt);
|
||||
erstelleKonto = new Modell(name, vorname, hashedPassword, email, teleN);
|
||||
|
||||
// Benutzer in der Datenbank speichern
|
||||
userDao.speichereUser(erstelleKonto);
|
||||
|
||||
// Nach dem Speichern kann die automatisch generierte ID verwendet werden
|
||||
System.out.println("Benutzer erstellt mit ID: " + erstelleKonto.getId());
|
||||
|
||||
view.showMessage();
|
||||
view.dispose();
|
||||
userWindwo = new UserWindow();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Erzeuge ein Salt
|
||||
private static String createSalt() {
|
||||
SecureRandom sr = new SecureRandom();
|
||||
byte[] salt = new byte[16];
|
||||
sr.nextBytes(salt);
|
||||
return Base64.getEncoder().encodeToString(salt);
|
||||
}
|
||||
|
||||
// Passwort hashen
|
||||
public static String hashPassword(String password, String salt) throws NoSuchAlgorithmException {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
md.update(Base64.getDecoder().decode(salt)); // Salt wird hinzugefügt
|
||||
byte[] hashedPassword = md.digest(password.getBytes());
|
||||
return Base64.getEncoder().encodeToString(hashedPassword); // Hashed Password wird zurückgegeben
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ControllerUserWindow {
|
||||
UserDao userDao;
|
||||
UserWindow userWindow;
|
||||
Modell user;
|
||||
|
||||
public ControllerUserWindow(Connection connection) {
|
||||
|
||||
this.userDao = new UserDaoImpl(connection);
|
||||
this.userWindow = new UserWindow();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DatenbankVerbindung {
|
||||
|
||||
// Statische Instanzvariable für die Singleton-Instanz
|
||||
private static DatenbankVerbindung verbindung = null;
|
||||
|
||||
// Instanzvariable für die eigentliche Datenbankverbindung
|
||||
private Connection connection;
|
||||
|
||||
// Privater Konstruktor, um die Instanziierung von außen zu verhindern
|
||||
private DatenbankVerbindung() throws SQLException, ClassNotFoundException {
|
||||
// Initialisiere die Verbindung zur Datenbank
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/banksystem", "root", "");
|
||||
}
|
||||
|
||||
// Synchronized, um Thread-Sicherheit zu gewährleisten
|
||||
public static synchronized DatenbankVerbindung getVerbindung() throws SQLException, ClassNotFoundException {
|
||||
if (verbindung == null) {
|
||||
verbindung = new DatenbankVerbindung();
|
||||
}
|
||||
return verbindung;
|
||||
}
|
||||
|
||||
// Methode, um die Datenbankverbindung zurückzugeben
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
// Methode, um die Verbindung zu schließen
|
||||
public void schliesseVerbindung() throws SQLException {
|
||||
if (this.connection != null && !this.connection.isClosed()) {
|
||||
this.connection.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.Color;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.awt.Font;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
public class EinzahlungsFenster extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
private JTextField betrag;
|
||||
private JButton einzahlen;
|
||||
|
||||
public EinzahlungsFenster() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 566, 509);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new LineBorder(new Color(64, 0, 64)));
|
||||
panel.setBackground(new Color(219, 219, 219));
|
||||
panel.setForeground(new Color(219, 219, 219));
|
||||
panel.setBounds(59, 54, 389, 328);
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel betrag_text = new JLabel("Betrag eingeben: ");
|
||||
betrag_text.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
betrag_text.setBounds(21, 40, 237, 36);
|
||||
panel.add(betrag_text);
|
||||
|
||||
betrag = new JTextField();
|
||||
betrag.setBounds(21, 87, 129, 36);
|
||||
panel.add(betrag);
|
||||
betrag.setColumns(10);
|
||||
|
||||
einzahlen = new JButton("Einzahlen");
|
||||
einzahlen.setBounds(21, 154, 168, 36);
|
||||
panel.add(einzahlen);
|
||||
}
|
||||
|
||||
public String getBetrag() {
|
||||
return betrag.getText();
|
||||
}
|
||||
|
||||
public void setBetrag(String betrag) {
|
||||
this.betrag.setText(betrag);
|
||||
}
|
||||
|
||||
public JButton getEinzahlen() {
|
||||
return einzahlen;
|
||||
}
|
||||
|
||||
public void zeige_fenster() {
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void schließe_fenster() {
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
public void zeige_Error(String error) {
|
||||
JOptionPane.showMessageDialog(this,error, "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
public void zeige_message(String message) {
|
||||
JOptionPane.showMessageDialog(this,message, "Einzahlung", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
public class GeldUeberweisung {
|
||||
private User sender;
|
||||
private User empfaenger;
|
||||
private double betrag;
|
||||
|
||||
public GeldUeberweisung(User sender, User empfaenger, double betrag) {
|
||||
this.sender = sender;
|
||||
this.empfaenger = empfaenger;
|
||||
this.betrag = betrag;
|
||||
}
|
||||
|
||||
public User getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public void setSender(User sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public User getEmpfaenger() {
|
||||
return empfaenger;
|
||||
}
|
||||
|
||||
public void setEmpfaenger(User empfaenger) {
|
||||
this.empfaenger = empfaenger;
|
||||
}
|
||||
|
||||
public double getBetrag() {
|
||||
return betrag;
|
||||
}
|
||||
|
||||
public void setBetrag(double betrag) {
|
||||
this.betrag = betrag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GeldUeberweisung [sender=" + sender + ", empfaenger=" + empfaenger + ", betrag=" + betrag + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.Color;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Font;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
public class HauptFenser extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
JLabel kontostand;
|
||||
JLabel user_Name;
|
||||
JButton einzahlen;
|
||||
JButton auszahlen;
|
||||
JButton ueberweisen;
|
||||
|
||||
public HauptFenser() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 913, 681);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new LineBorder(new Color(0, 0, 128)));
|
||||
panel.setBackground(new Color(219, 219, 219));
|
||||
panel.setBounds(99, 51, 595, 495);
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Willkommen ");
|
||||
lblNewLabel.setForeground(new Color(255, 0, 128));
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 18));
|
||||
lblNewLabel.setBounds(46, 38, 169, 65);
|
||||
panel.add(lblNewLabel);
|
||||
|
||||
JLabel kontosatnd_text = new JLabel("KontoStand: ");
|
||||
kontosatnd_text.setFont(new Font("Tahoma", Font.BOLD, 18));
|
||||
kontosatnd_text.setBounds(46, 189, 164, 65);
|
||||
panel.add(kontosatnd_text);
|
||||
|
||||
kontostand = new JLabel("");
|
||||
kontostand.setFont(new Font("Tahoma", Font.PLAIN, 15));
|
||||
kontostand.setBounds(178, 192, 300, 65);
|
||||
panel.add(kontostand);
|
||||
|
||||
user_Name = new JLabel("");
|
||||
user_Name.setForeground(new Color(0, 0, 0));
|
||||
user_Name.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
user_Name.setBounds(178, 55, 277, 37);
|
||||
panel.add(user_Name);
|
||||
|
||||
einzahlen = new JButton("Einzahlen");
|
||||
einzahlen.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
||||
einzahlen.setBounds(24, 349, 169, 58);
|
||||
panel.add(einzahlen);
|
||||
|
||||
auszahlen = new JButton("Auszahlen");
|
||||
auszahlen.setFont(new Font("Tahoma", Font.PLAIN, 15));
|
||||
auszahlen.setBounds(225, 349, 169, 58);
|
||||
panel.add(auszahlen);
|
||||
|
||||
ueberweisen = new JButton("Überweisen");
|
||||
ueberweisen.setFont(new Font("Tahoma", Font.PLAIN, 15));
|
||||
ueberweisen.setBounds(416, 349, 169, 58);
|
||||
panel.add(ueberweisen);
|
||||
}
|
||||
|
||||
public void zeige_HauptFenster() {
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void schließe_hauptFenster() {
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
public void set_user_name(String name) {
|
||||
user_Name.setText(name);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return user_Name.getText();
|
||||
}
|
||||
|
||||
public void set_user_kontostand(double kontostand_user) {
|
||||
kontostand.setText(kontostand_user + "");
|
||||
}
|
||||
|
||||
public String getUserkontostand() {
|
||||
return kontostand.getText();
|
||||
}
|
||||
|
||||
public JButton getEinzahlen() {
|
||||
return einzahlen;
|
||||
}
|
||||
|
||||
public JButton getAuszahlen() {
|
||||
return auszahlen;
|
||||
}
|
||||
|
||||
public JButton getUeberweisen() {
|
||||
return ueberweisen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class JTest {
|
||||
User obai;
|
||||
Konto obai_konto, obai_konto2;
|
||||
|
||||
User omar;
|
||||
Konto omar_konto;
|
||||
|
||||
Bank bank;
|
||||
|
||||
@BeforeEach
|
||||
void erstelle_Objekt() {
|
||||
obai = new User("Obai","albek");
|
||||
obai_konto = new Konto(0,obai);
|
||||
obai_konto2 = new Konto(0,obai);
|
||||
|
||||
omar = new User("Omar","Albek");
|
||||
omar_konto = new Konto(0,omar);
|
||||
|
||||
bank = new Bank("SparKasse");
|
||||
|
||||
bank.kunde_Hinzufuegen(obai);
|
||||
bank.kunde_Hinzufuegen(omar);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sucheKunden() throws Exception {
|
||||
|
||||
assertEquals(omar.toString(),bank.getKunde(1003));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testeinzahlen() throws Exception {
|
||||
obai_konto.einzahlen(50);
|
||||
assertEquals(50,obai_konto.getKontostand());
|
||||
|
||||
obai_konto2.einzahlen(100);
|
||||
assertEquals(100,obai_konto2.getKontostand());
|
||||
|
||||
omar_konto.einzahlen(100);
|
||||
assertEquals(100,omar_konto.getKontostand());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
public class Konto {
|
||||
|
||||
private static int konto_Nummer = 1000;
|
||||
private int konto_nummer;
|
||||
private double kontostand;
|
||||
private User inhaber;
|
||||
|
||||
public Konto(int kontostand, User inhaber) {
|
||||
this.konto_nummer = konto_Nummer++;
|
||||
this.kontostand = kontostand;
|
||||
this.inhaber = inhaber;
|
||||
}
|
||||
|
||||
public void einzahlen(double betrag) throws Exception {
|
||||
if (betrag <= 0)
|
||||
throw new Exception("ungültige Betrag");
|
||||
|
||||
this.kontostand += betrag;
|
||||
}
|
||||
|
||||
public void auszahlen(double betrag) throws Exception {
|
||||
if (betrag <= 0)
|
||||
throw new Exception("ungültige Betrag");
|
||||
|
||||
if (this.kontostand < betrag)
|
||||
throw new Exception("kein genug Geld auf dem Konto");
|
||||
|
||||
this.kontostand -= betrag;
|
||||
}
|
||||
|
||||
public double getKontostand() {
|
||||
return kontostand;
|
||||
}
|
||||
|
||||
public void setKontostand(double kontostand) {
|
||||
this.kontostand = kontostand;
|
||||
}
|
||||
|
||||
public User getInhaber() {
|
||||
return inhaber;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getKonto_nummer() {
|
||||
return konto_nummer;
|
||||
}
|
||||
|
||||
public void setKonto_nummer(int konto_nummer) {
|
||||
this.konto_nummer = konto_nummer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Konto [konto_nummer=" + konto_nummer + ", kontostand=" + kontostand + ", inhaber=" + inhaber + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Konto obai_konto = new Konto(0,new User("Obai", "Albek"));
|
||||
Bank sparkasse = new Bank("Sparkasse");
|
||||
ViewLogin loginFenster = new ViewLogin();
|
||||
HauptFenser userFenser = new HauptFenser();
|
||||
Controller test = new Controller(obai_konto,sparkasse,loginFenster,userFenser);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
public class Modell {
|
||||
private String name;
|
||||
private String vorname;
|
||||
private String password;
|
||||
private String email;
|
||||
private String teleN;
|
||||
private int kontoStand;
|
||||
private int id;
|
||||
|
||||
// Konstruktor ohne ID, für die erstmalige Erstellung des Kontos
|
||||
public Modell(String name, String vorname, String password, String email, String teleN) {
|
||||
this.name = name;
|
||||
this.vorname = vorname;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
this.teleN = teleN;
|
||||
this.kontoStand = 0;
|
||||
}
|
||||
|
||||
// Konstruktor mit ID (für spätere Verwendung, z.B. beim Abrufen aus der DB)
|
||||
public Modell(int id, String name, String vorname, String password, String email, String teleN, int kontoStand) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.vorname = vorname;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
this.teleN = teleN;
|
||||
this.kontoStand = kontoStand;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getVorname() {
|
||||
return vorname;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTeleN() {
|
||||
return teleN;
|
||||
}
|
||||
|
||||
public int getKontoStand() {
|
||||
return kontoStand;
|
||||
}
|
||||
|
||||
public void setKontoStand(int kontoStand) {
|
||||
this.kontoStand = kontoStand;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package BankSystemGUI;
|
||||
import java.awt.EventQueue;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) throws ClassNotFoundException, SQLException, NoSuchAlgorithmException {
|
||||
|
||||
if (DatenbankVerbindung.getVerbindung() != null)
|
||||
System.out.println("verbindung");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class User {
|
||||
|
||||
private String name;
|
||||
private String vorname;
|
||||
private int alter;
|
||||
private int kundennummer;
|
||||
private static int KUNDENNUMMER = 1000;
|
||||
private ArrayList<Konto> konten;
|
||||
|
||||
public User(String name, String vorname) {
|
||||
this.name = name;
|
||||
this.vorname = vorname;
|
||||
this.kundennummer = KUNDENNUMMER++;
|
||||
this.konten = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void konto_Hinzufuegen(Konto neuesKonto) {
|
||||
this.konten.add(neuesKonto);
|
||||
}
|
||||
|
||||
public ArrayList<Konto> getKonten(){
|
||||
return konten;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getVorname() {
|
||||
return vorname;
|
||||
}
|
||||
|
||||
public void setVorname(String vorname) {
|
||||
this.vorname = vorname;
|
||||
}
|
||||
|
||||
|
||||
public int getKundennummer() {
|
||||
return kundennummer;
|
||||
}
|
||||
|
||||
public void setKundennummer(int kundennummer) {
|
||||
this.kundennummer = kundennummer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User [name=" + name + ", vorname=" + vorname + ", alter=" + alter + ", kundennummer=" + kundennummer
|
||||
+ "]";
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package BankSystemGUI;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/* Was ist das?
|
||||
* - Die DAO (Data Access Object)-Interface wird für den Zugriff auf die Datenbank
|
||||
* - und das Speichern, Abrufen, Aktualisieren und Löschen von Benutzerdaten verantwortlich
|
||||
*/
|
||||
public interface UserDao {
|
||||
|
||||
// Benutzer speichern
|
||||
void speichereUser(Modell user)throws SQLException;
|
||||
|
||||
// Benutzer nach ID abrufen
|
||||
Modell getUserByName(int id)throws SQLException;
|
||||
|
||||
// Benutzer aktualisieren
|
||||
void updateUser(Modell user)throws SQLException;
|
||||
|
||||
// Benutzer löschen
|
||||
void löscheUser(int id)throws SQLException;
|
||||
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import java.sql.*;
|
||||
public class UserDaoImpl implements UserDao {
|
||||
|
||||
private Connection connection;
|
||||
|
||||
// Konstruktor für die Verbindung zur Datenbank
|
||||
public UserDaoImpl(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void speichereUser(Modell user) throws SQLException {
|
||||
String query = "INSERT INTO kunden (name, vorname, password, email, teleN, kontoStand) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
try (PreparedStatement stmt = connection.prepareStatement(query)) {
|
||||
stmt.setString(1, user.getName());
|
||||
stmt.setString(2, user.getVorname());
|
||||
stmt.setString(3, user.getPassword());
|
||||
stmt.setString(4, user.getEmail());
|
||||
stmt.setString(5, user.getTeleN());
|
||||
stmt.setInt(6, user.getKontoStand());
|
||||
|
||||
int affectedRows = stmt.executeUpdate();
|
||||
if (affectedRows == 0)
|
||||
throw new SQLException("Speichern des Benutzers fehlgeschlagen, keine Zeilen betroffen.");
|
||||
|
||||
// Abrufen der automatisch generierten ID aus der Datenbank
|
||||
Statement stmtID = connection.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT id FROM kunden");
|
||||
|
||||
if (rs.next())
|
||||
user.setId(rs.getInt(1)); // Setze die ID im Modell
|
||||
else
|
||||
throw new SQLException("Speichern des Benutzers fehlgeschlagen, keine ID zurückgegeben.");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Modell getUserByName(int id) throws SQLException {
|
||||
String query = "SELECT * FROM kunden WHERE id = ?";
|
||||
Modell user = null;
|
||||
try (PreparedStatement stmt = connection.prepareStatement(query)) {
|
||||
stmt.setInt(1, id);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
user = new Modell(rs.getInt("id"), rs.getString("name"), rs.getString("vorname"),
|
||||
rs.getString("password"), rs.getString("email"), rs.getString("teleN"),
|
||||
rs.getInt("kontoStand"));
|
||||
}
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(Modell user) throws SQLException {
|
||||
String query = "UPDATE kunden SET name = ?, vorname = ?, password = ?, email = ?, teleN = ?, kontoStand = ? WHERE id = ?";
|
||||
try (PreparedStatement stmt = connection.prepareStatement(query)) {
|
||||
stmt.setString(1, user.getName());
|
||||
stmt.setString(2, user.getVorname());
|
||||
stmt.setString(3, user.getPassword());
|
||||
stmt.setString(4, user.getEmail());
|
||||
stmt.setString(5, user.getTeleN());
|
||||
stmt.setInt(6, user.getKontoStand());
|
||||
stmt.setInt(7, user.getId());
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void löscheUser(int id) throws SQLException {
|
||||
String query = "DELETE FROM kunden WHERE id = ?";
|
||||
try (PreparedStatement stmt = connection.prepareStatement(query)) {
|
||||
stmt.setInt(1, id);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.JButton;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class UserWindow extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
JLabel begrüsseUser;
|
||||
JLabel userKontoStand;
|
||||
|
||||
public UserWindow(){
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setBounds(100, 100, 757, 654);
|
||||
this.contentPane = new JPanel();
|
||||
this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
this.setLocationRelativeTo(this);
|
||||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new LineBorder(new Color(128, 128, 0), 2));
|
||||
panel.setBackground(new Color(192, 192, 192));
|
||||
panel.setBounds(21, 23, 405, 377);
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
begrüsseUser = new JLabel("Willkommen ");
|
||||
begrüsseUser.setFont(new Font("Tahoma", Font.BOLD, 15));
|
||||
begrüsseUser.setForeground(new Color(0, 128, 0));
|
||||
begrüsseUser.setBounds(24, 23, 333, 28);
|
||||
panel.add(begrüsseUser);
|
||||
|
||||
userKontoStand = new JLabel("Kontostand: ");
|
||||
userKontoStand.setFont(new Font("Tahoma", Font.BOLD, 15));
|
||||
userKontoStand.setBounds(24, 82, 263, 47);
|
||||
panel.add(userKontoStand);
|
||||
|
||||
JButton btnNewButton = new JButton("Einzahlen");
|
||||
btnNewButton.setBounds(10, 249, 110, 23);
|
||||
panel.add(btnNewButton);
|
||||
|
||||
JButton btnNewButton_1 = new JButton("Auszahlen");
|
||||
|
||||
btnNewButton_1.setBounds(130, 249, 109, 23);
|
||||
panel.add(btnNewButton_1);
|
||||
|
||||
JButton btnNewButton_2 = new JButton("Überweisen");
|
||||
btnNewButton_2.setBounds(249, 249, 128, 23);
|
||||
panel.add(btnNewButton_2);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void showUserDaten(String name, String kontoStand) {
|
||||
|
||||
begrüsseUser.setText(begrüsseUser.getText() + " " + name);
|
||||
userKontoStand.setText(userKontoStand.getText() + " " + kontoStand);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new UserWindow();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.Color;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.SwingConstants;
|
||||
import java.awt.Font;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JButton;
|
||||
|
||||
public class ViewLogin extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
private JTextField name;
|
||||
private JTextField vorname;
|
||||
private JButton login;
|
||||
|
||||
public ViewLogin() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 600, 582);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new LineBorder(new Color(255, 0, 128)));
|
||||
panel.setBackground(new Color(219, 219, 219));
|
||||
panel.setBounds(159, 67, 261, 261);
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Name: ");
|
||||
lblNewLabel.setBounds(10, 65, 89, 26);
|
||||
panel.add(lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Login");
|
||||
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 15));
|
||||
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
lblNewLabel_1.setBounds(10, 11, 209, 26);
|
||||
panel.add(lblNewLabel_1);
|
||||
|
||||
name = new JTextField();
|
||||
name.setBounds(72, 65, 179, 26);
|
||||
panel.add(name);
|
||||
name.setColumns(10);
|
||||
|
||||
JLabel lblVorname = new JLabel("Vorname: ");
|
||||
lblVorname.setBounds(10, 110, 157, 26);
|
||||
panel.add(lblVorname);
|
||||
|
||||
vorname = new JTextField();
|
||||
vorname.setColumns(10);
|
||||
vorname.setBounds(72, 110, 179, 26);
|
||||
panel.add(vorname);
|
||||
|
||||
login = new JButton("Login");
|
||||
login.setBounds(10, 164, 99, 37);
|
||||
panel.add(login);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void zeige_login() {
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void schließe_login() {
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
public JButton getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name.getText();
|
||||
}
|
||||
|
||||
public void setName(JTextField name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getVorname() {
|
||||
return vorname.getText();
|
||||
}
|
||||
|
||||
public void setVorname(JTextField vorname) {
|
||||
this.vorname = vorname;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.JButton;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.SQLException;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class Window extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
JPanel contentPane;
|
||||
JTextField textFieldName;
|
||||
JTextField textFieldVorname;
|
||||
JTextField textFieldPassword;
|
||||
JTextField textFieldEmail;
|
||||
JTextField textFieldTeleN;
|
||||
JButton btnNewButton;
|
||||
|
||||
public Window() {
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setBounds(100, 100, 955, 664);
|
||||
this.setLocationRelativeTo(this);
|
||||
|
||||
contentPane = new JPanel();
|
||||
contentPane.setForeground(new Color(128, 128, 255));
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new LineBorder(new Color(255, 0, 0), 1, true));
|
||||
panel.setBackground(new Color(192, 192, 192));
|
||||
panel.setBounds(31, 23, 349, 343);
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Erstelle Konto");
|
||||
lblNewLabel.setBounds(21, 11, 120, 20);
|
||||
panel.add(lblNewLabel);
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
lblNewLabel.setForeground(new Color(128, 128, 255));
|
||||
lblNewLabel.setBackground(new Color(0, 0, 160));
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Name: ");
|
||||
lblNewLabel_1.setBounds(10, 42, 46, 14);
|
||||
panel.add(lblNewLabel_1);
|
||||
|
||||
textFieldName = new JTextField();
|
||||
textFieldName.setBounds(75, 39, 169, 20);
|
||||
panel.add(textFieldName);
|
||||
textFieldName.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("Vorname: ");
|
||||
lblNewLabel_2.setBounds(10, 80, 60, 14);
|
||||
panel.add(lblNewLabel_2);
|
||||
|
||||
textFieldVorname = new JTextField();
|
||||
textFieldVorname.setBounds(75, 77, 169, 20);
|
||||
panel.add(textFieldVorname);
|
||||
textFieldVorname.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("Password: ");
|
||||
lblNewLabel_3.setBounds(10, 123, 66, 14);
|
||||
panel.add(lblNewLabel_3);
|
||||
|
||||
JLabel lblNewLabel_3_1 = new JLabel("Email: ");
|
||||
lblNewLabel_3_1.setBounds(10, 170, 66, 14);
|
||||
panel.add(lblNewLabel_3_1);
|
||||
|
||||
JLabel lblNewLabel_4 = new JLabel("TeleN: ");
|
||||
lblNewLabel_4.setBounds(10, 215, 46, 14);
|
||||
panel.add(lblNewLabel_4);
|
||||
|
||||
btnNewButton = new JButton("Konto Erstellen");
|
||||
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 13));
|
||||
btnNewButton.setForeground(new Color(128, 128, 255));
|
||||
btnNewButton.setBounds(10, 262, 150, 23);
|
||||
panel.add(btnNewButton);
|
||||
|
||||
textFieldPassword = new JTextField();
|
||||
textFieldPassword.setBounds(75, 120, 169, 20);
|
||||
panel.add(textFieldPassword);
|
||||
textFieldPassword.setColumns(10);
|
||||
|
||||
textFieldEmail = new JTextField();
|
||||
textFieldEmail.setColumns(10);
|
||||
textFieldEmail.setBounds(75, 167, 169, 20);
|
||||
panel.add(textFieldEmail);
|
||||
|
||||
textFieldTeleN = new JTextField();
|
||||
textFieldTeleN.setColumns(10);
|
||||
textFieldTeleN.setBounds(75, 212, 169, 20);
|
||||
panel.add(textFieldTeleN);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void showError() {
|
||||
JOptionPane.showMessageDialog(this, "Dieser Konto existiert bereits! ", "Error Nachricht", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
}
|
||||
|
||||
public void showMessage() {
|
||||
JOptionPane.showMessageDialog(this, "Login war erfolgreich", "Login Erfolgreich", JOptionPane.PLAIN_MESSAGE);
|
||||
|
||||
}
|
||||
|
||||
public void setAction(ActionListener actionListener) {
|
||||
btnNewButton.addActionListener(actionListener);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package Übungen.MychatGUI;
|
||||
|
||||
public class CharRoom {
|
||||
|
||||
private User user1;
|
||||
private User user2;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package Übungen.MychatGUI;
|
||||
|
||||
public class User {
|
||||
|
||||
private String user_name;
|
||||
private int id;
|
||||
private static int ID = 1;
|
||||
private Status status;
|
||||
|
||||
public User(String user_name) {
|
||||
this.user_name = user_name;
|
||||
this.id = ID++;
|
||||
this.status = Status.OFFLINE; // Standardmäßig offline
|
||||
}
|
||||
|
||||
public String getUser_name() {
|
||||
return user_name;
|
||||
}
|
||||
|
||||
public void setUser_name(String user_name) {
|
||||
this.user_name = user_name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User [user_name=" + user_name + ", id=" + id + ", status=" + status.getDescription() + "]";
|
||||
}
|
||||
|
||||
// Enum für Status
|
||||
public enum Status {
|
||||
ONLINE("Online"),
|
||||
OFFLINE("Offline"),
|
||||
NICHT_STOEREN("Nicht Stören");
|
||||
|
||||
private String description;
|
||||
|
||||
// Konstruktor für enum
|
||||
Status(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
// Methode, um die Beschreibung zu holen
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package Übungen.Pac_Man;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class GameContainer extends JPanel implements Runnable {
|
||||
final static int WIDTH_WINDOW = 1000;
|
||||
final static int HEIGH_WINDOW = 700;
|
||||
Dimension fensterSize = new Dimension(WIDTH_WINDOW,HEIGH_WINDOW);
|
||||
|
||||
PacMan pacman;
|
||||
Geist[] geists = new Geist[3];
|
||||
|
||||
ArrayList<SpielKarte> waende;
|
||||
int[] x_pos = {116,95,230,230,650,755,650,755,230,230,878,720,107,107,878,731};
|
||||
int[] y_pos = {62,62,150,150,150,150,450,340,350,455,66,66,372,527,372,527};
|
||||
int[] width = {169,22,120,15,120,15,120,15,15,120,22,169,22,169,22,169};
|
||||
int[] height = {22,169,15,120,15,120,15,120,120,15,169,22,169,22,169,22};
|
||||
|
||||
|
||||
|
||||
Thread game;
|
||||
|
||||
|
||||
GameContainer(){
|
||||
this.waende = new ArrayList<>();
|
||||
draw_waende();
|
||||
draw_PacMan();
|
||||
this.setFocusable(true);
|
||||
this.setPreferredSize(fensterSize);
|
||||
this.addKeyListener(new Steuern());
|
||||
game = new Thread(this);
|
||||
game.start();
|
||||
|
||||
}
|
||||
|
||||
public void draw_PacMan() {
|
||||
pacman = new PacMan(WIDTH_WINDOW/2,HEIGH_WINDOW/2);
|
||||
}
|
||||
|
||||
public void draw_Geist() {
|
||||
|
||||
}
|
||||
|
||||
public void draw_waende() {
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
waende.add(new SpielKarte(x_pos[i],y_pos[i],width[i],height[i]));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void draw_Essen() {
|
||||
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
// Screen
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(0, 0, WIDTH_WINDOW, HEIGH_WINDOW);
|
||||
|
||||
// Zeichne die Wände
|
||||
for (SpielKarte w:waende )
|
||||
w.draw(g);
|
||||
|
||||
// Zeige Pacman
|
||||
pacman.draw(g);
|
||||
|
||||
}
|
||||
|
||||
public void move() {
|
||||
pacman.move();
|
||||
}
|
||||
|
||||
public void checkKollision() {
|
||||
for (SpielKarte w:waende) {
|
||||
if (pacman.intersects(w)) {
|
||||
pacman.set_x_bewegung(0);
|
||||
pacman.set_y_bewegung(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (pacman.y <= 5 || pacman.x <= 5) {
|
||||
pacman.set_x_bewegung(0);
|
||||
pacman.set_y_bewegung(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
move();
|
||||
checkKollision();
|
||||
repaint();
|
||||
Thread.sleep(25);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Steuern extends KeyAdapter{
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
pacman.keyPressed(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package Übungen.Pac_Man;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class GameFenster extends JFrame {
|
||||
|
||||
GameFenster(){
|
||||
|
||||
this.add(new GameContainer());
|
||||
this.setTitle("SnakeGame");
|
||||
this.setResizable(false);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.pack();
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package Übungen.Pac_Man;
|
||||
|
||||
public class Gameplay {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new GameFenster();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package Übungen.Pac_Man;
|
||||
|
||||
public class Geist {
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package Übungen.Pac_Man;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class PacMan extends Rectangle {
|
||||
|
||||
private static int pacMan_width = 20;
|
||||
private static int pacMan_height = 20;
|
||||
private int ybewegung;
|
||||
private int xbewegung;
|
||||
private int speed = 8;
|
||||
|
||||
PacMan(int x, int y) {
|
||||
|
||||
super(x, y, pacMan_width, pacMan_height);
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
g.setColor(Color.GREEN);
|
||||
g.fillRect(x, y, pacMan_width, pacMan_height);
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
|
||||
if (e.getKeyCode() == KeyEvent.VK_W) {
|
||||
set_y_bewegung(-speed);
|
||||
set_x_bewegung(0);
|
||||
}
|
||||
|
||||
if (e.getKeyCode() == KeyEvent.VK_S) {
|
||||
set_y_bewegung(speed);
|
||||
set_x_bewegung(0);
|
||||
}
|
||||
|
||||
if (e.getKeyCode() == KeyEvent.VK_D) {
|
||||
set_y_bewegung(0);
|
||||
set_x_bewegung(speed);
|
||||
}
|
||||
|
||||
if (e.getKeyCode() == KeyEvent.VK_A) {
|
||||
set_y_bewegung(0);
|
||||
set_x_bewegung(-speed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void set_y_bewegung(int y) {
|
||||
this.ybewegung = y;
|
||||
}
|
||||
|
||||
public void set_x_bewegung(int x) {
|
||||
this.xbewegung = x;
|
||||
}
|
||||
|
||||
public void move() {
|
||||
y += ybewegung;
|
||||
x += xbewegung;
|
||||
}
|
||||
|
||||
public void check_kollision() {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package Übungen.Pac_Man;
|
||||
import java.awt.*;
|
||||
|
||||
public class SpielKarte extends Rectangle {
|
||||
|
||||
SpielKarte(int x, int y, int width, int height){
|
||||
super(x,y,width,height);
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
g.setColor(Color.BLUE);
|
||||
g.fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package Übungen.Pac_Man;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JTree;
|
||||
|
||||
public class test extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
|
||||
|
||||
public test() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 1000, 700);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("New label");
|
||||
lblNewLabel.setBounds(230, 257, 169, 22);
|
||||
contentPane.add(lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("New label");
|
||||
lblNewLabel_1.setBounds(230, 95, 46, 144);
|
||||
contentPane.add(lblNewLabel_1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue