Ola pessoal !
Estou aqui desenvolvendo o jogo da velha, sou iniciante em java, o código esta montado porem da erro na hora quem que vou instanciar a classe lá na main.
Segue o erro:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot instantiate the type Tabuleiroat quadro.Tabuleiro.main(Tabuleiro.java:176)
Segue o codigo com problema:
package quadro;
import javax.swing.*;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
@SuppressWarnings("serial")
public abstract class Tabuleiro extends JFrame implements ActionListener {
int vez;
String simb;
private JButton mat[][];
private JPanel grade;
public Tabuleiro(){
super("Jogo da Velha");
((JComponent)getContentPane()).setBorder(new EmptyBorder(3,3,3,3));
initComponents();
configEvents();
configLayout();
cria_mat();
}
private void configLayout(){
this.add(grade);
this.grade.add(mat[3][3]);
this.grade.setLocation(470,200);
this.grade.setSize(400,400);
this.grade.setLayout(new GridLayout(3,3));
this.grade.setVisible(true);
}
private void configEvents(){
for(int i=0;i<9;i++){
mat[0][0].addActionListener(this);
mat[0][1].addActionListener(this);
mat[0][2].addActionListener(this);
mat[1][0].addActionListener(this);
mat[1][1].addActionListener(this);
mat[1][2].addActionListener(this);
mat[2][0].addActionListener(this);
mat[2][1].addActionListener(this);
mat[2][2].addActionListener(this);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
}
private void initComponents(){
grade = new JPanel();
mat = new JButton[3][3];
}
public void cria_mat(){
for(int l=0;l<3;l++){
for(int c=0;c<3;c++){
mat[l][l] = new JButton("");
}
}
}
public void jogador(int caracter){
if(vez == 0){
simb = "X";
vez = 1;
}else{
simb = "O";
vez =0;
}
mat[caracter][caracter].setText(simb);
mat[caracter][caracter].setEnabled(false);
}
public void b1actionPerformed(ActionEvent e) {
if(e.getSource() == mat[0][0]){
jogador(0);
}
}
public void b2actionPerformed(ActionEvent e) {
if(e.getSource() == mat[0][1]){
jogador(1);
}
}
public void b3actionPerformed(ActionEvent e) {
if(e.getSource() == mat[0][2]){
jogador(2);
}
}
public void b4actionPerformed(ActionEvent e) {
if(e.getSource() == mat[1][0]){
jogador(0);
}
}
public void b5actionPerformed(ActionEvent e) {
if(e.getSource() == mat[1][1]){
jogador(1);
}
}
public void b6actionPerformed(ActionEvent e) {
if(e.getSource() == mat[1][2]){
jogador(2);
}
}
public void b7actionPerformed(ActionEvent e) {
if(e.getSource() == mat[2][0]){
jogador(0);
}
}
public void b8actionPerformed(ActionEvent e) {
if(e.getSource() == mat[2][1]){
jogador(1);
}
}
public void b9actionPerformed(ActionEvent e) {
if(e.getSource() == mat[2][2]){
jogador(2);
}
}
public static void main(String[]args){
Tabuleiro Tabuleiro = new Tabuleiro();
Tabuleiro.setVisible(true);
}
}