From 40297298bb5cef7b5a5d51c00ddbe08a3076b9ce Mon Sep 17 00:00:00 2001 From: TRC9696 Date: Mon, 30 Jan 2023 17:40:50 +0100 Subject: [PATCH] refactoring: renamed button to fieldButton --- src/main/java/game/StartTicTacToeGame.java | 292 ++++++++++----------- 1 file changed, 146 insertions(+), 146 deletions(-) diff --git a/src/main/java/game/StartTicTacToeGame.java b/src/main/java/game/StartTicTacToeGame.java index 2809781..b7e8496 100644 --- a/src/main/java/game/StartTicTacToeGame.java +++ b/src/main/java/game/StartTicTacToeGame.java @@ -14,8 +14,8 @@ import Gui.gui; public class StartTicTacToeGame implements ActionListener{ - static JButton button,button2,button3,button4, - button5,button6,button7,button8,button9,backButton = new JButton(); + static JButton fieldButton,fieldButton2,fieldButton3,fieldButton4, + fieldButton5,fieldButton6,fieldButton7,fieldButton8,fieldButton9,backButton = new JButton(); boolean player1buttonPressed, player1button2Pressed, player1button3Pressed, player1button4Pressed, @@ -52,59 +52,59 @@ public class StartTicTacToeGame implements ActionListener{ label.setBounds(320,20,500,50); gui.Frame.add(label); - button = new JButton(); - button.setBackground(Color.white); - button.setBounds(200, 100, 100,100); - button.addActionListener(this); - gui.Frame.add(button); + fieldButton = new JButton(); + fieldButton.setBackground(Color.white); + fieldButton.setBounds(200, 100, 100,100); + fieldButton.addActionListener(this); + gui.Frame.add(fieldButton); - button2 = new JButton(); - button2.setBackground(Color.white); - button2.setBounds(350, 100, 100,100); - button2.addActionListener(this); - gui.Frame.add(button2); + fieldButton2 = new JButton(); + fieldButton2.setBackground(Color.white); + fieldButton2.setBounds(350, 100, 100,100); + fieldButton2.addActionListener(this); + gui.Frame.add(fieldButton2); - button3 = new JButton(); - button3.setBackground(Color.white); - button3.setBounds(500, 100, 100,100); - button3.addActionListener(this); - gui.Frame.add(button3); + fieldButton3 = new JButton(); + fieldButton3.setBackground(Color.white); + fieldButton3.setBounds(500, 100, 100,100); + fieldButton3.addActionListener(this); + gui.Frame.add(fieldButton3); - button4 = new JButton(); - button4.setBackground(Color.white); - button4.setBounds(200, 250, 100,100); - button4.addActionListener(this); - gui.Frame.add(button4); + fieldButton4 = new JButton(); + fieldButton4.setBackground(Color.white); + fieldButton4.setBounds(200, 250, 100,100); + fieldButton4.addActionListener(this); + gui.Frame.add(fieldButton4); - button5 = new JButton(); - button5.setBackground(Color.white); - button5.setBounds(350, 250, 100,100); - button5.addActionListener(this); - gui.Frame.add(button5); + fieldButton5 = new JButton(); + fieldButton5.setBackground(Color.white); + fieldButton5.setBounds(350, 250, 100,100); + fieldButton5.addActionListener(this); + gui.Frame.add(fieldButton5); - button6 = new JButton(); - button6.setBackground(Color.white); - button6.setBounds(500, 250, 100,100); - button6.addActionListener(this); - gui.Frame.add(button6); + fieldButton6 = new JButton(); + fieldButton6.setBackground(Color.white); + fieldButton6.setBounds(500, 250, 100,100); + fieldButton6.addActionListener(this); + gui.Frame.add(fieldButton6); - button7 = new JButton(); - button7.setBackground(Color.white); - button7.setBounds(200, 400, 100,100); - button7.addActionListener(this); - gui.Frame.add(button7); + fieldButton7 = new JButton(); + fieldButton7.setBackground(Color.white); + fieldButton7.setBounds(200, 400, 100,100); + fieldButton7.addActionListener(this); + gui.Frame.add(fieldButton7); - button8 = new JButton(); - button8.setBackground(Color.white); - button8.setBounds(350, 400, 100,100); - button8.addActionListener(this); - gui.Frame.add(button8); + fieldButton8 = new JButton(); + fieldButton8.setBackground(Color.white); + fieldButton8.setBounds(350, 400, 100,100); + fieldButton8.addActionListener(this); + gui.Frame.add(fieldButton8); - button9 = new JButton(); - button9.setBackground(Color.white); - button9.setBounds(500, 400, 100,100); - button9.addActionListener(this); - gui.Frame.add(button9); + fieldButton9 = new JButton(); + fieldButton9.setBackground(Color.white); + fieldButton9.setBounds(500, 400, 100,100); + fieldButton9.addActionListener(this); + gui.Frame.add(fieldButton9); backButton = new JButton(); backButton.setBackground(Color.white); @@ -133,181 +133,181 @@ public class StartTicTacToeGame implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { - if(e.getSource() == button) { + if(e.getSource() == fieldButton) { if(player1Turn) { - button.setForeground(Color.black); - button.setText("X"); - button.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton.setForeground(Color.black); + fieldButton.setText("X"); + fieldButton.setFont(new Font("arial", Font.PLAIN, 30)); player2Turn(); - button.setEnabled(false); + fieldButton.setEnabled(false); player1buttonPressed = true; check(); } else { - button.setForeground(Color.black); - button.setText("O"); - button.setFont(new Font("arial", Font.PLAIN, 30)); - button.setEnabled(false); + fieldButton.setForeground(Color.black); + fieldButton.setText("O"); + fieldButton.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton.setEnabled(false); player1Turn(); player2buttonPressed = true; check(); } } - else if(e.getSource() == button2) { + else if(e.getSource() == fieldButton2) { if(player1Turn) { - button2.setForeground(Color.black); - button2.setText("X"); - button2.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton2.setForeground(Color.black); + fieldButton2.setText("X"); + fieldButton2.setFont(new Font("arial", Font.PLAIN, 30)); player2Turn(); - button2.setEnabled(false); + fieldButton2.setEnabled(false); player1button2Pressed = true; check(); } else { - button2.setForeground(Color.black); - button2.setText("O"); - button2.setFont(new Font("arial", Font.PLAIN, 30)); - button2.setEnabled(false); + fieldButton2.setForeground(Color.black); + fieldButton2.setText("O"); + fieldButton2.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton2.setEnabled(false); player1Turn(); player2button2Pressed = true; check(); } } - else if(e.getSource() == button3) { + else if(e.getSource() == fieldButton3) { if(player1Turn) { - button3.setForeground(Color.black); - button3.setText("X"); - button3.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton3.setForeground(Color.black); + fieldButton3.setText("X"); + fieldButton3.setFont(new Font("arial", Font.PLAIN, 30)); player2Turn(); - button3.setEnabled(false); + fieldButton3.setEnabled(false); player1button3Pressed = true; check(); } else { - button3.setForeground(Color.black); - button3.setText("O"); - button3.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton3.setForeground(Color.black); + fieldButton3.setText("O"); + fieldButton3.setFont(new Font("arial", Font.PLAIN, 30)); player1Turn(); - button3.setEnabled(false); + fieldButton3.setEnabled(false); player2button3Pressed = true; check(); } } - else if(e.getSource() == button4) { + else if(e.getSource() == fieldButton4) { if(player1Turn) { - button4.setForeground(Color.black); - button4.setText("X"); - button4.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton4.setForeground(Color.black); + fieldButton4.setText("X"); + fieldButton4.setFont(new Font("arial", Font.PLAIN, 30)); player2Turn(); - button4.setEnabled(false); + fieldButton4.setEnabled(false); player1button4Pressed = true; check(); } else { - button4.setForeground(Color.black); - button4.setText("O"); - button4.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton4.setForeground(Color.black); + fieldButton4.setText("O"); + fieldButton4.setFont(new Font("arial", Font.PLAIN, 30)); player1Turn(); - button4.setEnabled(false); + fieldButton4.setEnabled(false); player2button4Pressed = true; check(); } } - else if(e.getSource() == button5) { + else if(e.getSource() == fieldButton5) { if(player1Turn) { - button5.setForeground(Color.black); - button5.setText("X"); - button5.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton5.setForeground(Color.black); + fieldButton5.setText("X"); + fieldButton5.setFont(new Font("arial", Font.PLAIN, 30)); player2Turn(); - button5.setEnabled(false); + fieldButton5.setEnabled(false); player1button5Pressed = true; check(); } else { - button5.setForeground(Color.black); - button5.setText("O"); - button5.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton5.setForeground(Color.black); + fieldButton5.setText("O"); + fieldButton5.setFont(new Font("arial", Font.PLAIN, 30)); player1Turn(); - button5.setEnabled(false); + fieldButton5.setEnabled(false); player2button5Pressed = true; check(); } } - else if(e.getSource() == button6) { + else if(e.getSource() == fieldButton6) { if(player1Turn) { - button6.setForeground(Color.black); - button6.setText("X"); - button6.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton6.setForeground(Color.black); + fieldButton6.setText("X"); + fieldButton6.setFont(new Font("arial", Font.PLAIN, 30)); player2Turn(); - button6.setEnabled(false); + fieldButton6.setEnabled(false); player1button6Pressed = true; check(); } else { - button6.setForeground(Color.black); - button6.setText("O"); - button6.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton6.setForeground(Color.black); + fieldButton6.setText("O"); + fieldButton6.setFont(new Font("arial", Font.PLAIN, 30)); player1Turn(); - button6.setEnabled(false); + fieldButton6.setEnabled(false); player2button6Pressed = true; check(); } } - else if(e.getSource() == button7) { + else if(e.getSource() == fieldButton7) { if(player1Turn) { - button7.setForeground(Color.black); - button7.setText("X"); - button7.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton7.setForeground(Color.black); + fieldButton7.setText("X"); + fieldButton7.setFont(new Font("arial", Font.PLAIN, 30)); player2Turn(); - button7.setEnabled(false); + fieldButton7.setEnabled(false); player1button7Pressed = true; check(); } else { - button7.setForeground(Color.black); - button7.setText("O"); - button7.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton7.setForeground(Color.black); + fieldButton7.setText("O"); + fieldButton7.setFont(new Font("arial", Font.PLAIN, 30)); player1Turn(); - button7.setEnabled(false); + fieldButton7.setEnabled(false); player2button7Pressed = true; check(); } } - else if(e.getSource() == button8) { + else if(e.getSource() == fieldButton8) { if(player1Turn) { - button8.setForeground(Color.black); - button8.setText("X"); - button8.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton8.setForeground(Color.black); + fieldButton8.setText("X"); + fieldButton8.setFont(new Font("arial", Font.PLAIN, 30)); player2Turn(); - button8.setEnabled(false); + fieldButton8.setEnabled(false); player1button8Pressed = true; check(); } else { - button8.setForeground(Color.black); - button8.setText("O"); - button8.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton8.setForeground(Color.black); + fieldButton8.setText("O"); + fieldButton8.setFont(new Font("arial", Font.PLAIN, 30)); player1Turn(); - button8.setEnabled(false); + fieldButton8.setEnabled(false); player2button8Pressed = true; check(); } } - else if(e.getSource() == button9) { + else if(e.getSource() == fieldButton9) { if(player1Turn) { - button9.setForeground(Color.black); - button9.setText("X"); - button9.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton9.setForeground(Color.black); + fieldButton9.setText("X"); + fieldButton9.setFont(new Font("arial", Font.PLAIN, 30)); player2Turn(); - button9.setEnabled(false); + fieldButton9.setEnabled(false); player1button9Pressed = true; check(); } else { - button9.setForeground(Color.black); - button9.setText("O"); - button9.setFont(new Font("arial", Font.PLAIN, 30)); - button9.setEnabled(false); + fieldButton9.setForeground(Color.black); + fieldButton9.setText("O"); + fieldButton9.setFont(new Font("arial", Font.PLAIN, 30)); + fieldButton9.setEnabled(false); player1Turn(); player2button9Pressed = true; check(); @@ -318,15 +318,15 @@ public class StartTicTacToeGame implements ActionListener{ public void player1Won() { label.setText("Spieler 1 hat gewonnen."); label.setBounds(250,20,500,50); - button.setVisible(false); - button2.setVisible(false); - button3.setVisible(false); - button4.setVisible(false); - button5.setVisible(false); - button6.setVisible(false); - button7.setVisible(false); - button8.setVisible(false); - button9.setVisible(false); + fieldButton.setVisible(false); + fieldButton2.setVisible(false); + fieldButton3.setVisible(false); + fieldButton4.setVisible(false); + fieldButton5.setVisible(false); + fieldButton6.setVisible(false); + fieldButton7.setVisible(false); + fieldButton8.setVisible(false); + fieldButton9.setVisible(false); //zurück button backButton.setVisible(true); @@ -335,15 +335,15 @@ public class StartTicTacToeGame implements ActionListener{ public void player2Won() { label.setText("Spieler 2 hat gewonnen."); label.setBounds(250,20,500,50); - button.setVisible(false); - button2.setVisible(false); - button3.setVisible(false); - button4.setVisible(false); - button5.setVisible(false); - button6.setVisible(false); - button7.setVisible(false); - button8.setVisible(false); - button9.setVisible(false); + fieldButton.setVisible(false); + fieldButton2.setVisible(false); + fieldButton3.setVisible(false); + fieldButton4.setVisible(false); + fieldButton5.setVisible(false); + fieldButton6.setVisible(false); + fieldButton7.setVisible(false); + fieldButton8.setVisible(false); + fieldButton9.setVisible(false); //zurück button backButton.setVisible(true);