imckinn40's Profile
Reputation: 0
Apprentice
- Group:
- Members
- Active Posts:
- 41 (0.1 per day)
- Joined:
- 19-March 12
- Profile Views:
- 180
- Last Active:
May 04 2012 05:38 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: I'm trying to get my tic tac toe code to show in label box
Posted 4 May 2012
Sorry I didn't know, but what was given to me didn't work I can get it to call the "Winner", but it won't call a "Draw". -
In Topic: I'm trying to get my tic tac toe code to show in label box
Posted 3 May 2012
I have tried to call the winner or draw in my tic tac toe code. Everything works. When I run the program the tic tac toe board appear, I can put in the Xs and Os. The text box should be blank until a winner or draw is called. It will show the winner but I can't get it to call draw with the text box being blank. When I use txtMove.setText the word "draw" stays in the text box and winner won't show. This is what I have, with this, it will call the winner but not a draw.
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Random; public class TicTacToe extends JPanel implements ActionListener { JButton btnButton1, btnButton2, btnButton3, btnButton4, btnButton5, btnButton6, btnButton7,btnButton8, btnButton9; JPanel panel1, panel2, panel3; JTextField txtMove=new JTextField(10); int turn =1; // 1 is O 2 X int cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9; int drawcount; public TicTacToe() { setLayout(new GridLayout(3,3)); panel1= new JPanel(); panel2= new JPanel(); panel3= new JPanel(); panel1.setLayout(new GridLayout(3,3)); cell1=cell2=cell3=cell4=cell5=cell6=cell7=cell8=cell9=0; btnButton1=new JButton(" "); btnButton2=new JButton(" "); btnButton3=new JButton(" "); btnButton4=new JButton(" "); btnButton5=new JButton(" "); btnButton6=new JButton(" "); btnButton7=new JButton(" "); btnButton8=new JButton(" "); btnButton9=new JButton(" "); btnButton1.setActionCommand("cell1"); btnButton2.setActionCommand("cell2"); btnButton3.setActionCommand("cell3"); btnButton4.setActionCommand("cell4"); btnButton5.setActionCommand("cell5"); btnButton6.setActionCommand("cell6"); btnButton7.setActionCommand("cell7"); btnButton8.setActionCommand("cell8"); btnButton9.setActionCommand("cell9"); btnButton1.addActionListener(this); btnButton2.addActionListener(this); btnButton3.addActionListener(this); btnButton4.addActionListener(this); btnButton5.addActionListener(this); btnButton6.addActionListener(this); btnButton7.addActionListener(this); btnButton8.addActionListener(this); btnButton9.addActionListener(this); panel1.add(btnButton1); panel1.add(btnButton2); panel1.add(btnButton3); panel1.add(btnButton4); panel1.add(btnButton5); panel1.add(btnButton6); panel1.add(btnButton7); panel1.add(btnButton8); panel1.add(btnButton9); panel3.add(txtMove); add(panel1); add(panel2); add(panel3); setPreferredSize(new Dimension(300,300)); } public void actionPerformed(ActionEvent event) { System.out.println(event.getActionCommand()); String s=event.getActionCommand(); String txtCaption=" "; if(turn==1) txtCaption="O"; else if(turn==2) txtCaption="X"; if(s=="cell1" && cell1==0) { btnButton1.setText(txtCaption); cell1=turn; } if(s=="cell2" && cell2==0) { btnButton2.setText(txtCaption); cell2=turn; } if(s=="cell3" && cell3==0) { btnButton3.setText(txtCaption); cell3=turn; } if(s=="cell4" && cell4==0) { btnButton4.setText(txtCaption); cell4=turn; } if(s=="cell5" && cell5==0) { btnButton5.setText(txtCaption); cell5=turn; } if(s=="cell6" && cell6==0) { btnButton6.setText(txtCaption); cell6=turn; } if(s=="cell7" && cell7==0) { btnButton7.setText(txtCaption); cell7=turn; } if(s=="cell8" && cell8==0) { btnButton8.setText(txtCaption); cell8=turn; } if(s=="cell9" && cell9==0) { btnButton9.setText(txtCaption); cell9=turn; } if(turn==1) turn=2; else if(turn==2) turn=1; if(cell1==1 && cell2==1 && cell3==1) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell4==1 && cell5==1 && cell6==1) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell7==1 && cell8==1 && cell9==1) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell1==1 && cell4==1 && cell7==1) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell2==1 && cell5==1 && cell8==1) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell3==1 && cell6==1 && cell9==1) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell1==1 && cell5==1 && cell9==1) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell3==1 && cell5==1 && cell7==1) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell1==2 && cell2==2 && cell3==2) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell4==2 && cell5==2 && cell6==2) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell7==2 && cell8==2 && cell9==2) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell1==2 && cell4==2 && cell7==2) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell2==2 && cell5==2 && cell8==2) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell3==2 && cell6==2 && cell9==2) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell1==2 && cell5==2 && cell9==2) { System.out.println("Winner"); txtMove.setText("Winner"); } if(cell3==2 && cell5==2 && cell7==2) { System.out.println("Winner"); txtMove.setText("winner"); } else System.out.println("Draw"); } } -
In Topic: My program will not work
Posted 2 May 2012
I got it, thank you all for your help. I got together. I thank you!!!!!
Thank you, I got and it's working. -
In Topic: My program will not work
Posted 2 May 2012
Please which two, I've changed almost everything and put it back when it didn't work. -
In Topic: My program will not work
Posted 2 May 2012
I made some changes and now I have one error,
' Program Name: Football Fever Scoreboard ' Author: Iris McKinney ' Date: April 25, 2012 ' Purpose: This application calculates the points ' scored during a football game by one team Option Strict On Public Class frmFootballFeverScoreboard ' The btnEnterScore event accepts and displays up to ten scores ' from the user, and then print last score. Private Sub btnEnterScore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterScore.Click Dim strScore As String Dim intScore As Integer Dim intFinalScore As Integer = 0 Dim strInputMessage As String = "Enter the score for game #" Dim strInputHeading As String = "Football Score" Dim strNormalMessage As String = "Enter the score for game #" Dim strNonNumericError As String = "Error - Enter a number for th score #" Dim strNegativeError As String = "Error please enter a positive number for score #" Dim Cnt As Integer Dim intTotalScore As Integer Dim strCancelClicked As String = "" Dim intMaxNumberOfEntries As Integer = 0 Dim intNumberOfEntries As Integer = 0 Do Dim strScore As Double = Double.Parse(InputBox(strInputMessage & intNumberOfEntries + 1, strInputHeading, " ")) If strScore = -10 Then Exit Do End If If IsNumeric(strScore) Then intFinalScore = CInt(strScore) If strScore > 0 Then lstScoreboard.Items.Add(strScore) intFinalScore += intScore intNumberOfEntries += 1 Cnt += 1 strInputMessage = strNormalMessage End If End If Loop Until intNumberOfEntries = 10 Or CInt(strScore) = -10 lblFinalScore.Visible = True If intNumberOfEntries > 1 Then 'decFinalScore = intTotalScore + decScore - 1 lblFinalScore.Text = "Average score per game is " & _ intFinalScore / Cnt Else lblFinalScore.Text = "no score entered" End If btnEnterScore.Enabled = True End Sub End Class
The error reads,
Error 1 Variable 'strScore' hides a variable in an enclosing block. C:\Users\best buy\Documents\Visual Basic Class\McKinneyFootballFever\McKinneyFootballFever\frmFootball Fever.vb 31 17 McKinneyFootballFever
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Click here to e-mail me
Friends
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
imckinn40 has no profile comments yet. Why not say hello?