Continued development of class "startLocalGame"
This commit is contained in:
parent
d2b33e8676
commit
238f5b7f2c
|
@ -1,6 +1,16 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class startLocalGame {
|
||||
// Funktionshilfen
|
||||
int semesterCounter = 1; // Semester Counter Label
|
||||
|
||||
// Grafiken
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
||||
ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
|
||||
|
||||
// Frame
|
||||
JFrame frame = new JFrame("Lokales Spiel");
|
||||
|
||||
|
@ -9,9 +19,9 @@ public class startLocalGame {
|
|||
JLabel semesterlable = new JLabel("Semester");
|
||||
JLabel leftPlayerName = new JLabel("Name");
|
||||
JLabel rightPlayerName = new JLabel("KI-Level");
|
||||
|
||||
// Grafiken
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
JLabel leftPlayerIcon = new JLabel(humanPlayerIcon);
|
||||
JLabel rightPlayerIcon = new JLabel(aiPlayerIcon);
|
||||
JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter));
|
||||
|
||||
// Buttons
|
||||
JButton backButton = new JButton(backButtonIcon);
|
||||
|
@ -23,12 +33,15 @@ public class startLocalGame {
|
|||
JButton rightPlayerRightButton = new JButton("->");
|
||||
JButton startButton = new JButton("Start!");
|
||||
|
||||
// Textfelder
|
||||
JTextField leftPlayerTextField = new JTextField(20);
|
||||
JTextField rightPlayerTextField = new JTextField(20);
|
||||
startLocalGame() {
|
||||
// Erstelle Frame
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(1500, 1000);
|
||||
|
||||
// Setzt den Layout-Manager auf null, um absolute Positionierung zu ermöglichen
|
||||
// Layout Manager (absolute ositionierung)
|
||||
frame.setLayout(null);
|
||||
|
||||
// Erstelle Label
|
||||
|
@ -38,17 +51,25 @@ public class startLocalGame {
|
|||
semesterlable.setBounds(700, 300, 200, 30);
|
||||
frame.add(semesterlable);
|
||||
|
||||
leftPlayerName.setBounds(50, 550, 200, 30);
|
||||
leftPlayerName.setBounds(50, 625, 200, 30);
|
||||
frame.add(leftPlayerName);
|
||||
|
||||
rightPlayerName.setBounds(750, 550, 200, 30);
|
||||
rightPlayerName.setBounds(1200, 625, 200, 30);
|
||||
frame.add(rightPlayerName);
|
||||
|
||||
leftPlayerIcon.setBounds(75, 400, 200, 128);
|
||||
frame.add(leftPlayerIcon);
|
||||
|
||||
rightPlayerIcon.setBounds(1225, 400, 200, 128);
|
||||
frame.add(rightPlayerIcon);
|
||||
|
||||
semesterCounterLabel.setBounds(725, 475, 50, 50); // zwischen den Up/Down-Buttons
|
||||
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
frame.add(semesterCounterLabel);
|
||||
|
||||
// Erstellt Buttons
|
||||
backButton.setBounds(1380, 20, 80, 80);
|
||||
frame.add(backButton);
|
||||
//backButton.setBorderPainted(false);
|
||||
//backButton.setContentAreaFilled(false);
|
||||
|
||||
leftPlayerLeftButton.setBounds(50, 450, 50, 50);
|
||||
frame.add(leftPlayerLeftButton);
|
||||
|
@ -71,6 +92,82 @@ public class startLocalGame {
|
|||
startButton.setBounds(700, 750, 100, 50);
|
||||
frame.add(startButton);
|
||||
|
||||
// Erstellt Textfelder
|
||||
leftPlayerTextField.setBounds(50, 650, 250, 50);
|
||||
frame.add(leftPlayerTextField);
|
||||
|
||||
rightPlayerTextField.setBounds(1200, 650, 250, 50);
|
||||
frame.add(rightPlayerTextField);
|
||||
|
||||
// ActionListener für die Buttons
|
||||
semesterUpButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (semesterCounter < 6) {
|
||||
semesterCounter++;
|
||||
semesterCounterLabel.setText(String.valueOf(semesterCounter));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
semesterDownButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (semesterCounter > 1) { // Verhindert, dass der Wert unter 1 fällt
|
||||
semesterCounter--;
|
||||
semesterCounterLabel.setText(String.valueOf(semesterCounter));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
|
||||
if(leftPlayerIcon.getIcon()==humanPlayerIcon) {
|
||||
leftPlayerIcon.setIcon(aiPlayerIcon);
|
||||
}else{
|
||||
leftPlayerIcon.setIcon(humanPlayerIcon);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
leftPlayerRightButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
|
||||
if(leftPlayerIcon.getIcon()==humanPlayerIcon) {
|
||||
leftPlayerIcon.setIcon(aiPlayerIcon);
|
||||
}else{
|
||||
leftPlayerIcon.setIcon(humanPlayerIcon);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rightPlayerLeftButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
|
||||
if(rightPlayerIcon.getIcon()==humanPlayerIcon) {
|
||||
rightPlayerIcon.setIcon(aiPlayerIcon);
|
||||
}else{
|
||||
rightPlayerIcon.setIcon(humanPlayerIcon);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rightPlayerRightButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
|
||||
if(rightPlayerIcon.getIcon()==humanPlayerIcon) {
|
||||
rightPlayerIcon.setIcon(aiPlayerIcon);
|
||||
}else{
|
||||
rightPlayerIcon.setIcon(humanPlayerIcon);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue