Estou desenvolvendo no Netbeans 7.1.2, o jogo da velha mas ele é um exemplo de livro acho que fiz igual ao livro mas ele não esta rodando
import javax.swing.JButton;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Sony
*/
public class Velha extends javax.swing.JFrame {
private int jogador;
private int qt;
private int mat[] [] = new int[3] [3];
private JButton b[] = new JButton[9];
/**
* Creates new form Velha
*/
public Velha() {
initComponents();
jogador = 1;
qt = 1;
b[0] = b_1;
b[1] = b_2;
b[2] = b_3;
b[3] = b_4;
b[4] = b_5;
b[5] = b_6;
b[6] = b_7;
b[7] = b_8;
b[8] = b_9;
}
public void jogada(javax.swing.JButton b, int 1, int c){
b.setEnabled(false);
if (jogador == 1){
b.setText("x");
jogador = 0;
mat[1] [c] = 1;
checkJogada(1);
}else{
b.setText("o");
jogador = 1;
mat[1] [c] = 2;
checkJogada(2);
}
qt++;
}
private void checkJogada(int x){
if ( vitoria(x) == true){
JOptionPane.showMessageDialog(null,"Jogador "+x+" "+
"Venceu ","Vitoria",JOptionPane.INFORMATION_MESSAGE);
fimJogo();
}
}
private boolean vitoria(int x){
for(int i=0; i < mat.length; i++){
if ((mat[i] [0] == x)&& (mat[i] [1] == x) &&(mat[i] [2] == x))
return(true);
if ((mat[0] [i] == x)&& (mat[1] [i] == x) &&(mat[2] [i] == x))
return(true);
}
if ((mat[0] [0] == x)&& (mat[1] [1] == x)&&(mat[2] [2] == x))
return (true);
if ((mat[0] [2] == x)&& (mat[1] [1] == x)&&(mat[2] [0] == x))
return (true);
return(false);
}
private void fimJogo(){
for(int i =0; i < 9; i++){
b[i].setEnabled(false);
}
}
private void limpa(){
for(int i =0; i < 9; i++){
b[i].setText(" ");
b[i].setEnabled(true);
}
for(int i =0; i < 3; i++ )
for(int k=0; k < 3; k++){
mat[i] [k] = 0;
}
}
/**
* 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
b_1 = new javax.swing.JButton();
b_2 = new javax.swing.JButton();
b_3 = new javax.swing.JButton();
b_4 = new javax.swing.JButton();
b_5 = new javax.swing.JButton();
b_6 = new javax.swing.JButton();
b_7 = new javax.swing.JButton();
b_8 = new javax.swing.JButton();
b_9 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
b_1.setText("b_1");
b_1.setName("b_1");
b_1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_1ActionPerformed(evt);
}
});
b_2.setText("b_2");
b_2.setName("b_2");
b_2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_2ActionPerformed(evt);
}
});
b_3.setText("b_3");
b_3.setName("b_3");
b_4.setText("b_4");
b_4.setName("b_4");
b_5.setText("b_5");
b_5.setName("b_5");
b_6.setText("b_6");
b_6.setName("b_6");
b_7.setText("b_7");
b_7.setName("b_7");
b_8.setText("b_8");
b_8.setName("b_8");
b_9.setText("b_9");
b_9.setName("b_9");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(37, 37, 37)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(b_1)
.addComponent(b_4)
.addComponent(b_7))
.addGap(36, 36, 36)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(b_2)
.addComponent(b_5)
.addComponent(b_8))
.addGap(39, 39, 39)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(b_9)
.addComponent(b_6)
.addComponent(b_3))
.addContainerGap(111, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(75, 75, 75)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(b_1)
.addComponent(b_2)
.addComponent(b_3))
.addGap(41, 41, 41)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(b_4)
.addComponent(b_5)
.addComponent(b_6))
.addGap(42, 42, 42)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(b_7)
.addComponent(b_8)
.addComponent(b_9))
.addContainerGap(26, Short.MAX_VALUE))
);
jMenu1.setText("Opção");
jMenuItem1.setText("Novo Jogo");
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Sair");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void b_1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jogada(b_1, 0, 0);
}
private void b_2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jogada(b_2, 0, 1);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* 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(Velha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Velha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Velha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Velha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Velha().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton b_1;
private javax.swing.JButton b_2;
private javax.swing.JButton b_3;
private javax.swing.JButton b_4;
private javax.swing.JButton b_5;
private javax.swing.JButton b_6;
private javax.swing.JButton b_7;
private javax.swing.JButton b_8;
private javax.swing.JButton b_9;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
private void jogada(JButton b_1, int i, int i0) {
throw new UnsupportedOperationException("Not yet implemented");
}
}
Erro abaixo:
run:
Exception in thread “AWT-EventQueue-0” java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: Array.setEnabled
at Velha.(Velha.java:38)
at Velha$3.run(Velha.java:282)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
CONSTRUÍDO COM SUCESSO (tempo total: 5 segundos)
Tentei ser o mais detalhista no erro