Pessoal eu fiz uma classe, essa classe tinha intuito de criar um jogo da velha, dai eu fiz umas classes internas para tratar os eventos de um Botao mas não deu certo, alguem ai pode me ajudar o codigo está logo a baixo…
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
public class Velha extends JFrame {
private JButton buttons[ ] = new JButton[ 9 ] ;
private JPanel panel ;
private JLabel label ;
private boolean vez = false ;
public Velha(){
super( " JOGO DA VELHA " ) ;
panel = new JPanel() ;
label = new JLabel( "VEZ DO JOGADOR x" ) ;
add( panel, BorderLayout.CENTER ) ;
add( label,BorderLayout.SOUTH ) ;
panel.setLayout( new GridLayout(3, 3, 5, 5 ) ) ;
for( int i = 0 ; i < buttons.length ; i++ ){
buttons[ i ] = new JButton() ;
buttons[ i ].setFont(new Font( "serif", Font.PLAIN, 15 ) ) ;
panel.add( buttons[ i ] ) ;
}
buttons[ 0 ].addActionListener(new HandLerButton0()) ;
buttons[ 1 ].addActionListener(new HandLerButton1()) ;
buttons[ 2 ].addActionListener(new HandLerButton2()) ;
buttons[ 3 ].addActionListener(new HandLerButton3()) ;
buttons[ 4 ].addActionListener(new HandLerButton4()) ;
buttons[ 5 ].addActionListener(new HandLerButton5()) ;
buttons[ 6 ].addActionListener(new HandLerButton6()) ;
buttons[ 7 ].addActionListener(new HandLerButton7()) ;
buttons[ 8 ].addActionListener(new HandLerButton8()) ;
panel.setSize(250, 250) ;
panel.setVisible(true) ;
}
private class HandLerButton1 implements ActionListener{
public void actionPerformed(ActionEvent eve){
if( vez ){
if( eve.getSource() == buttons[ 1 ] ){
buttons[ 1 ].setText(" 0 ") ;
if( buttons[ 0 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 1 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " ||
buttons[ 3 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " ||
buttons[ 6 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 1 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( o ) FOI O VENCEDOR ") ;
}
vez = false ;
label.setText( " Vez Do JOGADOR x " ) ;
}
else
{
buttons[ 1 ].setText(" X ") ;
if( buttons[ 0 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 1 ].getText() == " x " && buttons[ 3 ].getText() == " x " ||
buttons[ 3 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 5 ].getText() == " x " ||
buttons[ 6 ].getText() == " x " && buttons[ 7 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 3 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 1 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 7 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 5 ].getText() == " x " && buttons[ 8 ].getText() == " x "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( x ) FOI O VENCEDOR ") ;
}
vez = true ;
label.setText( " Vez DO JOGADOR o " ) ;
}
}
}
}
private class HandLerButton2 implements ActionListener{
public void actionPerformed(ActionEvent eve){
if( vez ){
if( eve.getSource() == buttons[ 1 ] ){
buttons[ 2 ].setText(" 0 ") ;
if( buttons[ 0 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 1 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " ||
buttons[ 3 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " ||
buttons[ 6 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 1 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( o ) FOI O VENCEDOR ") ;
}
vez = false ;
label.setText( " Vez Do JOGADOR x " ) ;
}
else
{
buttons[ 2 ].setText(" X ") ;
if( buttons[ 0 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 1 ].getText() == " x " && buttons[ 3 ].getText() == " x " ||
buttons[ 3 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 5 ].getText() == " x " ||
buttons[ 6 ].getText() == " x " && buttons[ 7 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 3 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 1 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 7 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 5 ].getText() == " x " && buttons[ 8 ].getText() == " x "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( x ) FOI O VENCEDOR ") ;
}
vez = true ;
label.setText( " Vez DO JOGADOR o " ) ;
}
}
}
}
private class HandLerButton3 implements ActionListener{
public void actionPerformed(ActionEvent eve){
if( vez ){
if( eve.getSource() == buttons[ 1 ] ){
buttons[ 3 ].setText(" 0 ") ;
if( buttons[ 0 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 1 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " ||
buttons[ 3 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " ||
buttons[ 6 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 1 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( o ) FOI O VENCEDOR ") ;
}
vez = false ;
label.setText( " Vez Do JOGADOR x " ) ;
}
else
{
buttons[ 3 ].setText(" X ") ;
if( buttons[ 0 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 1 ].getText() == " x " && buttons[ 3 ].getText() == " x " ||
buttons[ 3 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 5 ].getText() == " x " ||
buttons[ 6 ].getText() == " x " && buttons[ 7 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 3 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 1 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 7 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 5 ].getText() == " x " && buttons[ 8 ].getText() == " x "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( x ) FOI O VENCEDOR ") ;
}
vez = true ;
label.setText( " Vez DO JOGADOR o " ) ;
}
}
}
}
private class HandLerButton4 implements ActionListener{
public void actionPerformed(ActionEvent eve){
if( vez ){
if( eve.getSource() == buttons[ 1 ] ){
buttons[ 4 ].setText(" 0 ") ;
if( buttons[ 0 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 1 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " ||
buttons[ 3 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " ||
buttons[ 6 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 1 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( o ) FOI O VENCEDOR ") ;
}
vez = false ;
label.setText( " Vez Do JOGADOR x " ) ;
}
else
{
buttons[ 4 ].setText(" X ") ;
if( buttons[ 0 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 1 ].getText() == " x " && buttons[ 3 ].getText() == " x " ||
buttons[ 3 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 5 ].getText() == " x " ||
buttons[ 6 ].getText() == " x " && buttons[ 7 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 3 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 1 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 7 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 5 ].getText() == " x " && buttons[ 8 ].getText() == " x "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( x ) FOI O VENCEDOR ") ;
}
vez = true ;
label.setText( " Vez DO JOGADOR o " ) ;
}
}
}
}
private class HandLerButton5 implements ActionListener{
public void actionPerformed(ActionEvent eve){
if( vez ){
if( eve.getSource() == buttons[ 1 ] ){
buttons[ 5 ].setText(" 0 ") ;
if( buttons[ 0 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 1 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " ||
buttons[ 3 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " ||
buttons[ 6 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 1 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( o ) FOI O VENCEDOR ") ;
}
vez = false ;
label.setText( " Vez Do JOGADOR x " ) ;
}
else
{
buttons[ 5 ].setText(" X ") ;
if( buttons[ 0 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 1 ].getText() == " x " && buttons[ 3 ].getText() == " x " ||
buttons[ 3 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 5 ].getText() == " x " ||
buttons[ 6 ].getText() == " x " && buttons[ 7 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 3 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 1 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 7 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 5 ].getText() == " x " && buttons[ 8 ].getText() == " x "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( x ) FOI O VENCEDOR ") ;
}
vez = true ;
label.setText( " Vez DO JOGADOR o " ) ;
}
}
}
}
private class HandLerButton6 implements ActionListener{
public void actionPerformed(ActionEvent eve){
if( vez ){
if( eve.getSource() == buttons[ 1 ] ){
buttons[ 6 ].setText(" 0 ") ;
if( buttons[ 0 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 1 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " ||
buttons[ 3 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " ||
buttons[ 6 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 1 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( o ) FOI O VENCEDOR ") ;
}
vez = false ;
label.setText( " Vez Do JOGADOR x " ) ;
}
else
{
buttons[ 6 ].setText(" X ") ;
if( buttons[ 0 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 1 ].getText() == " x " && buttons[ 3 ].getText() == " x " ||
buttons[ 3 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 5 ].getText() == " x " ||
buttons[ 6 ].getText() == " x " && buttons[ 7 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 3 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 1 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 7 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 5 ].getText() == " x " && buttons[ 8 ].getText() == " x "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( x ) FOI O VENCEDOR ") ;
}
vez = true ;
label.setText( " Vez DO JOGADOR o " ) ;
}
}
}
}
private class HandLerButton7 implements ActionListener{
public void actionPerformed(ActionEvent eve){
if( vez ){
if( eve.getSource() == buttons[ 1 ] ){
buttons[ 7 ].setText(" 0 ") ;
if( buttons[ 0 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 1 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " ||
buttons[ 3 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " ||
buttons[ 6 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 1 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( o ) FOI O VENCEDOR ") ;
}
vez = false ;
label.setText( " Vez Do JOGADOR x " ) ;
}
else
{
buttons[ 7 ].setText(" X ") ;
if( buttons[ 0 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 1 ].getText() == " x " && buttons[ 3 ].getText() == " x " ||
buttons[ 3 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 5 ].getText() == " x " ||
buttons[ 6 ].getText() == " x " && buttons[ 7 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 3 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 1 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 7 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 5 ].getText() == " x " && buttons[ 8 ].getText() == " x "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( x ) FOI O VENCEDOR ") ;
}
vez = true ;
label.setText( " Vez DO JOGADOR o " ) ;
}
}
}
}
private class HandLerButton8 implements ActionListener{
public void actionPerformed(ActionEvent eve){
if( vez ){
if( eve.getSource() == buttons[ 1 ] ){
buttons[ 8 ].setText(" 0 ") ;
if( buttons[ 0 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 1 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " ||
buttons[ 3 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " ||
buttons[ 6 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 1 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( o ) FOI O VENCEDOR ") ;
}
vez = false ;
label.setText( " Vez Do JOGADOR x " ) ;
}
else
{
buttons[ 8 ].setText(" X ") ;
if( buttons[ 0 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 1 ].getText() == " x " && buttons[ 3 ].getText() == " x " ||
buttons[ 3 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 5 ].getText() == " x " ||
buttons[ 6 ].getText() == " x " && buttons[ 7 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 3 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 1 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 7 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 5 ].getText() == " x " && buttons[ 8 ].getText() == " x "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( x ) FOI O VENCEDOR ") ;
}
vez = true ;
label.setText( " Vez DO JOGADOR o " ) ;
}
}
}
}
private class HandLerButton0 implements ActionListener{
public void actionPerformed(ActionEvent eve){
if( vez ){
if( eve.getSource() == buttons[ 1 ] ){
buttons[ 0 ].setText(" 0 ") ;
if( buttons[ 0 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 1 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " ||
buttons[ 3 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " ||
buttons[ 6 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 " ||
buttons[ 0 ].getText() == " 0 " && buttons[ 3 ].getText() == " 0 " && buttons[ 6 ].getText() == " 0 " ||
buttons[ 1 ].getText() == " 0 " && buttons[ 4 ].getText() == " 0 " && buttons[ 7 ].getText() == " 0 " ||
buttons[ 2 ].getText() == " 0 " && buttons[ 5 ].getText() == " 0 " && buttons[ 8 ].getText() == " 0 "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( o ) FOI O VENCEDOR ") ;
}
vez = false ;
label.setText( " Vez Do JOGADOR x " ) ;
}
else
{
buttons[ 0 ].setText(" X ") ;
if( buttons[ 0 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 1 ].getText() == " x " && buttons[ 3 ].getText() == " x " ||
buttons[ 3 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 5 ].getText() == " x " ||
buttons[ 6 ].getText() == " x " && buttons[ 7 ].getText() == " x " && buttons[ 8 ].getText() == " x " ||
buttons[ 0 ].getText() == " x " && buttons[ 3 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 6 ].getText() == " x " ||
buttons[ 1 ].getText() == " x " && buttons[ 4 ].getText() == " x " && buttons[ 7 ].getText() == " x " ||
buttons[ 2 ].getText() == " x " && buttons[ 5 ].getText() == " x " && buttons[ 8 ].getText() == " x "){
JOptionPane.showMessageDialog(panel, " O JOGADOR ( x ) FOI O VENCEDOR ") ;
}
vez = true ;
label.setText( " Vez DO JOGADOR o " ) ;
}
}
}
}
}