add controlpanel
commit
100cf4712c
|
|
@ -5,18 +5,50 @@ import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
public class ButtonAufgebenListener extends JFrame implements ActionListener{
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.App;
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame.BoardMode;
|
||||||
|
|
||||||
|
public class ButtonAufgebenListener extends JFrame implements ActionListener {
|
||||||
|
|
||||||
|
private static final Logger logger = LogManager.getLogger(App.class);
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
private SpielFrame sf;
|
||||||
|
private Game g;
|
||||||
|
|
||||||
public ButtonAufgebenListener() {
|
public ButtonAufgebenListener(SpielFrame sf, Game g) {
|
||||||
|
this.sf = sf;
|
||||||
|
this.g = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
Object source = e.getSource();
|
||||||
|
|
||||||
|
g.stopClock();
|
||||||
|
|
||||||
|
// weil nur der aktive Spieler button drücken darf
|
||||||
|
if (source == sf.getAufgeben()) {
|
||||||
|
logger.info("Spieler 1 will aufgeben.");
|
||||||
|
sf.getAufgeben2().setEnabled(false);
|
||||||
|
sf.showResult("Spieler 2 hat gewonnen!");
|
||||||
|
} else if (source == sf.getAufgeben2()) {
|
||||||
|
logger.info("Spieler 2 will aufgeben.");
|
||||||
|
sf.getAufgeben().setEnabled(false);
|
||||||
|
sf.showResult("Spieler 1 hat gewonnen!");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sf.setBoardMode(BoardMode.finished);
|
||||||
|
|
||||||
|
sf.setButtonsActions();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,12 @@ public class ButtonMovePieceListener implements ActionListener {
|
||||||
this.game.stopClock();
|
this.game.stopClock();
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
this.sf.setBoardMode(BoardMode.finished);
|
||||||
this.sf.enableControlPanelButtons();
|
this.sf.enableControlPanelButtons();
|
||||||
this.sf.showDraw();
|
this.sf.showResult("Unentschieden!");
|
||||||
} else if (this.game.isMate()) {
|
} else if (this.game.isMate()) {
|
||||||
this.game.stopClock();
|
this.game.stopClock();
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
this.sf.setBoardMode(BoardMode.finished);
|
||||||
this.sf.enableControlPanelButtons();
|
this.sf.enableControlPanelButtons();
|
||||||
this.sf.showWin(game.getActivePlayer());
|
this.sf.showResult("Spieler "+game.getActivePlayer()+" hat gewonnen!");
|
||||||
} else {
|
} else {
|
||||||
this.sf.setBoardMode(BoardMode.normal);
|
this.sf.setBoardMode(BoardMode.normal);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package de.mannheim.th.chess.ui;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import com.github.bhlangonijr.chesslib.Piece;
|
|
||||||
import com.github.bhlangonijr.chesslib.Square;
|
import com.github.bhlangonijr.chesslib.Square;
|
||||||
import com.github.bhlangonijr.chesslib.move.Move;
|
import com.github.bhlangonijr.chesslib.move.Move;
|
||||||
import com.github.bhlangonijr.chesslib.move.MoveList;
|
import com.github.bhlangonijr.chesslib.move.MoveList;
|
||||||
|
|
@ -57,7 +56,7 @@ public class SpielFrame extends JFrame {
|
||||||
private ArrayList<JButton> buttons = new ArrayList<>();
|
private ArrayList<JButton> buttons = new ArrayList<>();
|
||||||
private HashMap<JButton, String> belegungen = new HashMap<>();
|
private HashMap<JButton, String> belegungen = new HashMap<>();
|
||||||
private JPanel panelLinks, panelRechts, contentPane, controlPanel;
|
private JPanel panelLinks, panelRechts, contentPane, controlPanel;
|
||||||
private JButton undo, undo2;
|
private JButton undo, undo2, aufgeben, aufgeben2;
|
||||||
private JTextArea ausgabe;
|
private JTextArea ausgabe;
|
||||||
private Game game;
|
private Game game;
|
||||||
private Clock clock;
|
private Clock clock;
|
||||||
|
|
@ -273,19 +272,9 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (JButton b : buttons) {
|
||||||
|
panelLinks.add(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDraw() {
|
|
||||||
JFrame frame = new JFrame("Result");
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
frame.setSize(300, 150);
|
|
||||||
frame.setLayout(null);
|
|
||||||
|
|
||||||
// JLabel jl = new JLabel(String.format("%d - %d", player / 2, player % 2));
|
|
||||||
// jl.setBounds(50, 30, 200, 25);
|
|
||||||
// jl.setFont(new Font("Tahoma", Font.BOLD, 20));
|
|
||||||
// frame.add(jl);
|
|
||||||
// frame.setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showWin(int player) {
|
public void showWin(int player) {
|
||||||
|
|
@ -301,6 +290,14 @@ public class SpielFrame extends JFrame {
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showResult(String res) {
|
||||||
|
|
||||||
|
ausgabe.setFont(new Font("Calibri", Font.BOLD, 40));
|
||||||
|
ausgabe.setForeground(new Color(178, 34, 34));
|
||||||
|
ausgabe.setText(" "+res);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public int showPromotion() {
|
public int showPromotion() {
|
||||||
final int[] result = { -1 };
|
final int[] result = { -1 };
|
||||||
|
|
||||||
|
|
@ -419,15 +416,14 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
||||||
|
|
||||||
JButton aufgeben = new JButton("Aufgeben");
|
aufgeben2 = new JButton("Aufgeben");
|
||||||
aufgeben.setBackground(Color.LIGHT_GRAY);
|
aufgeben2.setBackground(Color.LIGHT_GRAY);
|
||||||
aufgeben.setForeground(Color.BLACK);
|
aufgeben2.setForeground(Color.BLACK);
|
||||||
aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16));
|
aufgeben2.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||||
aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT);
|
aufgeben2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
aufgebenUndo.add(aufgeben);
|
|
||||||
|
|
||||||
// Button-Listener
|
aufgeben2.addActionListener(new ButtonAufgebenListener(this, this.game));
|
||||||
aufgeben.addActionListener(new ButtonAufgebenListener());
|
aufgebenUndo.add(aufgeben2);
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
||||||
|
|
||||||
|
|
@ -528,15 +524,14 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
||||||
|
|
||||||
JButton aufgeben = new JButton("Aufgeben");
|
aufgeben = new JButton("Aufgeben");
|
||||||
aufgeben.setBackground(Color.LIGHT_GRAY);
|
aufgeben.setBackground(Color.LIGHT_GRAY);
|
||||||
aufgeben.setForeground(Color.BLACK);
|
aufgeben.setForeground(Color.BLACK);
|
||||||
aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16));
|
aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||||
aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT);
|
aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
aufgebenUndo.add(aufgeben);
|
aufgeben.addActionListener(new ButtonAufgebenListener(this, this.game));
|
||||||
|
|
||||||
// Button-Listener
|
aufgebenUndo.add(aufgeben);
|
||||||
aufgeben.addActionListener(new ButtonAufgebenListener());
|
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
||||||
|
|
||||||
|
|
@ -621,4 +616,60 @@ public class SpielFrame extends JFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JButton getAufgeben() {
|
||||||
|
return aufgeben;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAufgeben(JButton aufgeben) {
|
||||||
|
this.aufgeben = aufgeben;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getAufgeben2() {
|
||||||
|
return aufgeben2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAufgeben2(JButton aufgeben2) {
|
||||||
|
this.aufgeben2 = aufgeben2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMode(BoardMode mode) {
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inverts the Enabled property of the controlpanelButtons
|
||||||
|
*/
|
||||||
|
public void enableControlPanelButtons() {
|
||||||
|
for (Component c : this.controlPanel.getComponents()) {
|
||||||
|
if (c instanceof JButton) {
|
||||||
|
c.setEnabled(!c.isEnabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the buttons to the boardpanel
|
||||||
|
*/
|
||||||
|
public void applyBoardButtons() {
|
||||||
|
for (JButton b : buttons) {
|
||||||
|
panelLinks.add(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getAufgeben() {
|
||||||
|
return aufgeben;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAufgeben(JButton aufgeben) {
|
||||||
|
this.aufgeben = aufgeben;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getAufgeben2() {
|
||||||
|
return aufgeben2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAufgeben2(JButton aufgeben2) {
|
||||||
|
this.aufgeben2 = aufgeben2;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue