Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could anyone help me document this code by writing comments? /* */ package java_Tic_Tac_Toe; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JOptionPane; /** * * Written By

Could anyone help me document this code by writing comments?

/*

*/ package java_Tic_Tac_Toe;

import java.awt.Color; import javax.swing.JFrame; import javax.swing.JOptionPane;

/** * * Written By Shehriyar. */ public class java_Tic_Tac_Toe extends javax.swing.JFrame {

private String startGame ="X"; private int xCount = 0; private int oCount = 0; boolean checker; /** * new form java_Tic_Tac_Toe */ public java_Tic_Tac_Toe() { initComponents(); } private void gameScore() { jlblPlayerX.setText(String.valueOf(xCount)); jlblPlayerO.setText(String.valueOf(oCount)); }

//private void enableFalse() //{ // jbtnTic1.setEnabled(false); // jbtnTic2.setEnabled(false); // jbtnTic3.setEnabled(false); // jbtnTic4.setEnabled(false); // jbtnTic5.setEnabled(false); // jbtnTic6.setEnabled(false); // jbtnTic7.setEnabled(false); // jbtnTic8.setEnabled(false); // jbtnTic9.setEnabled(false); // // //} private void choose_a_Player() { if (startGame.equalsIgnoreCase("X")) { startGame ="O"; } else { startGame ="X"; } } private void winningGame() { String b1 = jbtnTic1.getText(); String b2 = jbtnTic2.getText(); String b3 = jbtnTic3.getText(); String b4 = jbtnTic4.getText(); String b5 = jbtnTic5.getText(); String b6 = jbtnTic6.getText(); String b7 = jbtnTic7.getText(); String b8 = jbtnTic8.getText(); String b9 = jbtnTic9.getText(); if (b1==("X") & b2 == ("X") & b3 == ("X")) { JOptionPane.showMessageDialog(this,"Player X Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); jbtnTic1.setBackground(Color.YELLOW); jbtnTic2.setBackground(Color.YELLOW); jbtnTic3.setBackground(Color.YELLOW); xCount++; gameScore(); } if (b4==("X") && b5 == ("X") && b6 == ("X")) { JOptionPane.showMessageDialog(this,"Player X Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); xCount++; gameScore(); jbtnTic4.setBackground(Color.CYAN); jbtnTic5.setBackground(Color.CYAN); jbtnTic6.setBackground(Color.CYAN); } if (b7==("X") && b8 == ("X") && b9 == ("X")) { JOptionPane.showMessageDialog(this,"Player X Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); xCount++; gameScore(); jbtnTic7.setBackground(Color.CYAN); jbtnTic8.setBackground(Color.CYAN); jbtnTic9.setBackground(Color.CYAN); } if (b1==("X") && b4 == ("X") && b7 == ("X")) { JOptionPane.showMessageDialog(this,"Player X Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); xCount++; gameScore(); jbtnTic1.setBackground(Color.MAGENTA); jbtnTic4.setBackground(Color.MAGENTA); jbtnTic7.setBackground(Color.MAGENTA); } if (b2==("X") && b5 == ("X") && b8 == ("X")) { JOptionPane.showMessageDialog(this,"Player X Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); xCount++; gameScore(); jbtnTic2.setBackground(Color.PINK); jbtnTic5.setBackground(Color.PINK); jbtnTic8.setBackground(Color.PINK); } if (b3==("X") && b6 == ("X") && b9 == ("X")) { JOptionPane.showMessageDialog(this,"Player X Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); xCount++; gameScore(); jbtnTic3.setBackground(Color.MAGENTA); jbtnTic6.setBackground(Color.MAGENTA); jbtnTic9.setBackground(Color.MAGENTA); } if (b1==("X") && b5 == ("X") && b9 == ("X")) { JOptionPane.showMessageDialog(this,"Player X Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); xCount++; gameScore(); jbtnTic1.setBackground(Color.PINK); jbtnTic5.setBackground(Color.PINK); jbtnTic9.setBackground(Color.PINK); } if (b3==("X") && b5 == ("X") && b7 == ("X")) { JOptionPane.showMessageDialog(this,"Player X Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); xCount++; gameScore(); jbtnTic3.setBackground(Color.cyan); jbtnTic5.setBackground(Color.cyan); jbtnTic7.setBackground(Color.cyan); } if (b1==("O") && b2 == ("O") && b3 == ("O")) { JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); oCount++; gameScore(); jbtnTic1.setBackground(Color.PINK); jbtnTic2.setBackground(Color.PINK); jbtnTic3.setBackground(Color.PINK); } if (b4==("O") && b5 == ("O") && b6 == ("O")) { JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); oCount++; gameScore(); jbtnTic4.setBackground(Color.YELLOW); jbtnTic5.setBackground(Color.YELLOW); jbtnTic6.setBackground(Color.YELLOW); } if (b7==("O") && b8 == ("O") && b9 == ("O")) { JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); oCount++; gameScore(); jbtnTic7.setBackground(Color.MAGENTA); jbtnTic8.setBackground(Color.MAGENTA); jbtnTic9.setBackground(Color.MAGENTA); // enableFalse(); } if (b1==("O") && b4 == ("O") && b7 == ("O")) { JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); oCount++; gameScore(); jbtnTic1.setBackground(Color.MAGENTA); jbtnTic4.setBackground(Color.MAGENTA); jbtnTic7.setBackground(Color.MAGENTA); // enableFalse(); } if (b2==("O") && b5 == ("O") && b8 == ("O")) { JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); oCount++; gameScore(); jbtnTic2.setBackground(Color.MAGENTA); jbtnTic5.setBackground(Color.MAGENTA); jbtnTic8.setBackground(Color.MAGENTA); //enableFalse(); } if (b3==("O") && b6 == ("O") && b9 == ("O")) { JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); oCount++; gameScore(); jbtnTic3.setBackground(Color.PINK); jbtnTic6.setBackground(Color.PINK); jbtnTic9.setBackground(Color.PINK); // enableFalse(); } if (b1==("O") && b5 == ("O") && b9 == ("O")) { JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); oCount++; gameScore(); jbtnTic1.setBackground(Color.PINK); jbtnTic5.setBackground(Color.PINK); jbtnTic9.setBackground(Color.PINK); // enableFalse(); } if (b3==("O") && b5 == ("O") && b7 == ("O")) { JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE); oCount++; gameScore(); jbtnTic3.setBackground(Color.PINK); jbtnTic5.setBackground(Color.PINK); jbtnTic7.setBackground(Color.PINK); // enableFalse(); } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // private void initComponents() {

jPanel4 = new javax.swing.JPanel(); jPanel5 = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); jPanel6 = new javax.swing.JPanel(); jPanel8 = new javax.swing.JPanel(); jbtnExit = new javax.swing.JButton(); jbtnNewGame = new javax.swing.JButton(); jbtnReset = new javax.swing.JButton(); jPanel10 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jlblPlayerX = new javax.swing.JLabel(); jlblPlayerO = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jPanel7 = new javax.swing.JPanel(); jLabel2 = new javax.swing.JLabel(); jPanel9 = new javax.swing.JPanel(); jbtnTic6 = new javax.swing.JButton(); jbtnTic4 = new javax.swing.JButton(); jbtnTic5 = new javax.swing.JButton(); jbtnTic3 = new javax.swing.JButton(); jbtnTic2 = new javax.swing.JButton(); jbtnTic1 = new javax.swing.JButton(); jbtnTic8 = new javax.swing.JButton(); jbtnTic7 = new javax.swing.JButton(); jbtnTic9 = new javax.swing.JButton(); jButton12 = new javax.swing.JButton(); jButton13 = new javax.swing.JButton();

jPanel4.setBackground(new java.awt.Color(95, 158, 160));

jPanel5.setBackground(new java.awt.Color(95, 158, 160)); jPanel5.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 1400, Short.MAX_VALUE) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) ); jPanel4Layout.setVerticalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 800, Short.MAX_VALUE) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) );

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jPanel1.setBackground(new java.awt.Color(95, 158, 160)); jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jPanel6.setBackground(new java.awt.Color(95, 158, 160)); jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED))); jPanel6.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jPanel8.setBackground(new java.awt.Color(95, 158, 160)); jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED))); jPanel8.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jbtnExit.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnExit.setText("Exit"); jbtnExit.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnExit.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnExit.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnExit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnExitActionPerformed(evt); } }); jPanel8.add(jbtnExit, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 130, 310, 110));

jbtnNewGame.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnNewGame.setText("New Game"); jbtnNewGame.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnNewGame.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnNewGame.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnNewGame.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNewGameActionPerformed(evt); } }); jPanel8.add(jbtnNewGame, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 630, 110));

jbtnReset.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnReset.setText("Reset"); jbtnReset.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnReset.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnReset.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnReset.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnResetActionPerformed(evt); } }); jPanel8.add(jbtnReset, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, 310, 110));

jPanel6.add(jPanel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 260, 650, 250));

jPanel10.setBackground(new java.awt.Color(95, 158, 160)); jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED))); jPanel10.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 66)); // NOI18N jLabel1.setText("Player O:"); jPanel10.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 130, -1, -1));

jlblPlayerX.setFont(new java.awt.Font("Tahoma", 1, 66)); // NOI18N jlblPlayerX.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jlblPlayerX.setText("0"); jlblPlayerX.setOpaque(true); jPanel10.add(jlblPlayerX, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 20, 260, 90));

jlblPlayerO.setFont(new java.awt.Font("Tahoma", 1, 66)); // NOI18N jlblPlayerO.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jlblPlayerO.setText("0"); jlblPlayerO.setOpaque(true); jPanel10.add(jlblPlayerO, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 130, 260, 90));

jLabel5.setFont(new java.awt.Font("Tahoma", 1, 66)); // NOI18N jLabel5.setText("Player X:"); jPanel10.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, -1));

jPanel6.add(jPanel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 650, 240));

jPanel1.add(jPanel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 120, 670, 520));

jPanel7.setBackground(new java.awt.Color(95, 158, 160)); jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED))); jPanel7.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jLabel2.setFont(new java.awt.Font("Tahoma", 1, 66)); // NOI18N jLabel2.setForeground(new java.awt.Color(255, 255, 255)); jLabel2.setText("Java Advanced Tic Tac Toe Game"); jPanel7.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 0, -1, -1));

jPanel1.add(jPanel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 1340, 90));

jPanel9.setBackground(new java.awt.Color(95, 158, 160)); jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED))); jPanel9.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jbtnTic6.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnTic6.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnTic6.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnTic6.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnTic6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnTic6ActionPerformed(evt); } }); jPanel9.add(jbtnTic6, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 180, -1, -1));

jbtnTic4.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnTic4.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnTic4.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnTic4.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnTic4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnTic4ActionPerformed(evt); } }); jPanel9.add(jbtnTic4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 180, -1, -1));

jbtnTic5.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnTic5.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnTic5.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnTic5.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnTic5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnTic5ActionPerformed(evt); } }); jPanel9.add(jbtnTic5, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 180, -1, -1));

jbtnTic3.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnTic3.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnTic3.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnTic3.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnTic3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnTic3ActionPerformed(evt); } }); jPanel9.add(jbtnTic3, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 10, -1, -1));

jbtnTic2.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnTic2.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnTic2.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnTic2.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnTic2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnTic2ActionPerformed(evt); } }); jPanel9.add(jbtnTic2, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 10, -1, -1));

jbtnTic1.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnTic1.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnTic1.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnTic1.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnTic1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnTic1ActionPerformed(evt); } }); jPanel9.add(jbtnTic1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, -1));

jbtnTic8.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnTic8.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnTic8.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnTic8.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnTic8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnTic8ActionPerformed(evt); } }); jPanel9.add(jbtnTic8, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 350, -1, -1));

jbtnTic7.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnTic7.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnTic7.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnTic7.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnTic7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnTic7ActionPerformed(evt); } }); jPanel9.add(jbtnTic7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 350, -1, -1));

jbtnTic9.setFont(new java.awt.Font("Tahoma", 1, 96)); // NOI18N jbtnTic9.setMaximumSize(new java.awt.Dimension(200, 158)); jbtnTic9.setMinimumSize(new java.awt.Dimension(200, 158)); jbtnTic9.setPreferredSize(new java.awt.Dimension(200, 158)); jbtnTic9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnTic9ActionPerformed(evt); } }); jPanel9.add(jbtnTic9, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 350, -1, -1));

jPanel1.add(jPanel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, 660, 520));

jButton12.setFont(new java.awt.Font("Tahoma", 0, 96)); // NOI18N jButton12.setMaximumSize(new java.awt.Dimension(200, 158)); jButton12.setMinimumSize(new java.awt.Dimension(200, 158)); jButton12.setPreferredSize(new java.awt.Dimension(200, 158)); jPanel1.add(jButton12, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 120, 310, 110));

jButton13.setFont(new java.awt.Font("Tahoma", 0, 96)); // NOI18N jButton13.setMaximumSize(new java.awt.Dimension(200, 158)); jButton13.setMinimumSize(new java.awt.Dimension(200, 158)); jButton13.setPreferredSize(new java.awt.Dimension(200, 158)); jPanel1.add(jButton13, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, 310, 110));

getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1400, 800));

pack(); setLocationRelativeTo(null); }//

private void jbtnNewGameActionPerformed(java.awt.event.ActionEvent evt) { jbtnTic1.setEnabled(true); jbtnTic2.setEnabled(true); jbtnTic3.setEnabled(true); jbtnTic4.setEnabled(true); jbtnTic5.setEnabled(true); jbtnTic6.setEnabled(true); jbtnTic7.setEnabled(true); jbtnTic8.setEnabled(true); jbtnTic9.setEnabled(true); jbtnTic1.setText(""); jbtnTic2.setText(""); jbtnTic3.setText(""); jbtnTic4.setText(""); jbtnTic5.setText(""); jbtnTic6.setText(""); jbtnTic7.setText(""); jbtnTic8.setText(""); jbtnTic9.setText(""); jlblPlayerX.setText("0"); jlblPlayerO.setText("0"); jbtnTic1.setBackground(Color.LIGHT_GRAY); jbtnTic2.setBackground(Color.LIGHT_GRAY); jbtnTic3.setBackground(Color.LIGHT_GRAY); jbtnTic4.setBackground(Color.LIGHT_GRAY); jbtnTic5.setBackground(Color.LIGHT_GRAY); jbtnTic6.setBackground(Color.LIGHT_GRAY); jbtnTic7.setBackground(Color.LIGHT_GRAY); jbtnTic8.setBackground(Color.LIGHT_GRAY); jbtnTic9.setBackground(Color.LIGHT_GRAY); } private JFrame frame; private void jbtnExitActionPerformed(java.awt.event.ActionEvent evt) { frame = new JFrame("Exit"); if(JOptionPane.showConfirmDialog(frame, "Confirm if you want to exit","Tic Tac Toe", JOptionPane.YES_NO_OPTION ) == JOptionPane.YES_NO_OPTION) { System.exit(0); } }

private void jbtnResetActionPerformed(java.awt.event.ActionEvent evt) { jbtnTic1.setEnabled(true); jbtnTic2.setEnabled(true); jbtnTic3.setEnabled(true); jbtnTic4.setEnabled(true); jbtnTic5.setEnabled(true); jbtnTic6.setEnabled(true); jbtnTic7.setEnabled(true); jbtnTic8.setEnabled(true); jbtnTic9.setEnabled(true); jbtnTic1.setText(""); jbtnTic2.setText(""); jbtnTic3.setText(""); jbtnTic4.setText(""); jbtnTic5.setText(""); jbtnTic6.setText(""); jbtnTic7.setText(""); jbtnTic8.setText(""); jbtnTic9.setText(""); jbtnTic1.setBackground(Color.LIGHT_GRAY); jbtnTic2.setBackground(Color.LIGHT_GRAY); jbtnTic3.setBackground(Color.LIGHT_GRAY); jbtnTic4.setBackground(Color.LIGHT_GRAY); jbtnTic5.setBackground(Color.LIGHT_GRAY); jbtnTic6.setBackground(Color.LIGHT_GRAY); jbtnTic7.setBackground(Color.LIGHT_GRAY); jbtnTic8.setBackground(Color.LIGHT_GRAY); jbtnTic9.setBackground(Color.LIGHT_GRAY); }

private void jbtnTic1ActionPerformed(java.awt.event.ActionEvent evt) {

jbtnTic1.setText(startGame); if (startGame.equalsIgnoreCase("X")) { //jbtnTic1.setForeground(Color.BLACK); //jbtnTic1.setBackground(Color.YELLOW); checker = false; } else { //jbtnTic1.setForeground(Color.BLACK); //jbtnTic1.setBackground(Color.RED); checker = true; } choose_a_Player(); winningGame(); //jbtnTic1.setEnabled(false); }

private void jbtnTic2ActionPerformed(java.awt.event.ActionEvent evt) { jbtnTic2.setText(startGame); if (startGame.equalsIgnoreCase("X")) { //jbtnTic2.setForeground(Color.BLACK); // jbtnTic1.setBackground(Color.YELLOW); checker = false; } else { //jbtnTic2.setForeground(Color.BLACK); // jbtnTic2.setBackground(Color.RED); checker = true; } choose_a_Player(); winningGame(); //jbtnTic2.setEnabled(false); }

private void jbtnTic3ActionPerformed(java.awt.event.ActionEvent evt) { jbtnTic3.setText(startGame); if (startGame.equalsIgnoreCase("X")) { //jbtnTic3.setForeground(Color.BLACK); // jbtnTic3.setBackground(Color.YELLOW); checker = false; } else { //jbtnTic3.setForeground(Color.BLACK); //jbtnTic3.setBackground(Color.RED); checker = true; } choose_a_Player(); winningGame(); // jbtnTic3.setEnabled(false); }

private void jbtnTic4ActionPerformed(java.awt.event.ActionEvent evt) { jbtnTic4.setText(startGame); if (startGame.equalsIgnoreCase("X")) { //jbtnTic4.setForeground(Color.GREEN); checker = true; } else { //jbtnTic4.setForeground(Color.BLUE); checker = true; } choose_a_Player(); winningGame(); // jbtnTic4.setEnabled(false); }

private void jbtnTic5ActionPerformed(java.awt.event.ActionEvent evt) { jbtnTic5.setText(startGame); if (startGame.equalsIgnoreCase("X")) { //jbtnTic5.setForeground(Color.GREEN); checker = false; } else { //jbtnTic5.setForeground(Color.BLUE); checker = true; } choose_a_Player(); winningGame(); //jbtnTic5.setEnabled(false); }

private void jbtnTic6ActionPerformed(java.awt.event.ActionEvent evt) { jbtnTic6.setText(startGame); if (startGame.equalsIgnoreCase("X")) { // jbtnTic6.setForeground(Color.GREEN); checker = false; } else { //jbtnTic6.setForeground(Color.BLUE); checker = true; } choose_a_Player(); winningGame(); //jbtnTic6.setEnabled(false); }

private void jbtnTic7ActionPerformed(java.awt.event.ActionEvent evt) { jbtnTic7.setText(startGame); if (startGame.equalsIgnoreCase("X")) { //jbtnTic7.setForeground(Color.GREEN); checker = false; } else { //jbtnTic7.setForeground(Color.BLUE); checker = true; } choose_a_Player(); winningGame(); //jbtnTic7.setEnabled(false); }

private void jbtnTic8ActionPerformed(java.awt.event.ActionEvent evt) { jbtnTic8.setText(startGame); if (startGame.equalsIgnoreCase("X")) { //jbtnTic8.setForeground(Color.GREEN); checker = false; } else { //jbtnTic8.setForeground(Color.BLUE); checker = true; } choose_a_Player(); winningGame(); }

private void jbtnTic9ActionPerformed(java.awt.event.ActionEvent evt) { jbtnTic9.setText(startGame); if (startGame.equalsIgnoreCase("X")) { checker = false; } else { checker = true; } choose_a_Player(); winningGame(); }

/** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(java_Tic_Tac_Toe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(java_Tic_Tac_Toe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(java_Tic_Tac_Toe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(java_Tic_Tac_Toe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //

/* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new java_Tic_Tac_Toe().setVisible(true); } }); }

// Variables declaration - do not modify private javax.swing.JButton jButton12; private javax.swing.JButton jButton13; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel5; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel10; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JPanel jPanel7; private javax.swing.JPanel jPanel8; private javax.swing.JPanel jPanel9; private javax.swing.JButton jbtnExit; private javax.swing.JButton jbtnNewGame; private javax.swing.JButton jbtnReset; private javax.swing.JButton jbtnTic1; private javax.swing.JButton jbtnTic2; private javax.swing.JButton jbtnTic3; private javax.swing.JButton jbtnTic4; private javax.swing.JButton jbtnTic5; private javax.swing.JButton jbtnTic6; private javax.swing.JButton jbtnTic7; private javax.swing.JButton jbtnTic8; private javax.swing.JButton jbtnTic9; private javax.swing.JLabel jlblPlayerO; private javax.swing.JLabel jlblPlayerX; // End of variables declaration }

Step by Step Solution

3.46 Rating (149 Votes )

There are 3 Steps involved in it

Step: 1

To document the provided Java Tic Tac Toe code Ill add comments explaining each part of the code This program implements a simple Tic Tac Toe game using Java Swing GUI Written By Shehriyar Importing n... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Smith and Roberson Business Law

Authors: Richard A. Mann, Barry S. Roberts

15th Edition

1285141903, 1285141903, 9781285141909, 978-0538473637

More Books

Students also viewed these Programming questions

Question

Why is the national security argument for tariffs questionable?

Answered: 1 week ago