Duvidas

Bom dia Galera tenho esse codigo aqui em java correto?porme fui passar para android e como ainda nao tenho muito conehcimento nao consigo saber o que tenho q tirar para que pare de dar pau…lembrando q no android a interface é colocada separada do codigo java…

package com.jogoDaVelha;

//import java.awt.BorderLayout;
//import java.awt.Color;
//import java.awt.Font;
//import java.awt.GraphicsEnvironment;
//import java.awt.GridLayout;
//import java.awt.HeadlessException;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
//import java.awt.event.WindowAdapter;
//import java.awt.event.WindowEvent;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

//import javax.swing.Box;
//import javax.swing.JButton;
//import javax.swing.JFrame;
//import javax.swing.JMenu;
//import javax.swing.JMenuBar;
//import javax.swing.JMenuItem;
//import javax.swing.JOptionPane;
//import javax.swing.JPanel;
//import javax.swing.WindowConstants;

public class JogoDaVelha extends Activity implements ActionListener {
private static final long serialVersionUID = 1L;
private JButton[][] botoes;
private String vez;
private boolean terminou;
private static final Color COR_X = Color.RED;
private static final Color COR_O = Color.BLUE;

public JogoDaVelha() throws HeadlessException {
    super("Jogo da Velha");
    // Define tamanho da janela
    setSize(200, 240);
    // Define menu
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Jogo");
    JMenuItem iteNovo = new JMenuItem("Novo Jogo");
    iteNovo.addActionListener(this);
    menu.add(iteNovo);
    menu.addSeparator();
    JMenuItem iteSair = new JMenuItem("Sair");
    iteSair.addActionListener(this);
    menu.add(iteSair);
    menuBar.add(menu);
    setJMenuBar(menuBar);
    // Panel com os botões
    criarNovoJogo();
    // Chama método para centralizar janela
    centralizarJanela();
    // Prepara saída da janela
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 
    addWindowListener(new WindowAdapter() {
        public final void windowClosing(final WindowEvent e) {
            if (JOptionPane.showConfirmDialog(null, "Deseja fechar o jogo da velha?", "Fechar", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
                System.exit(0);
            }
        }
    });
}

private void criarNovoJogo() {
    getContentPane().removeAll();
    // Define layout da janela
    int borda = 25;
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(Box.createVerticalStrut(borda), BorderLayout.NORTH);
    getContentPane().add(Box.createVerticalStrut(borda), BorderLayout.SOUTH);
    getContentPane().add(Box.createHorizontalStrut(borda), BorderLayout.EAST);
    getContentPane().add(Box.createHorizontalStrut(borda), BorderLayout.WEST);
    JPanel pJogo = new JPanel();
    pJogo.setLayout(new GridLayout(3, 3));
    // Cria conjunto de botões
    botoes = new JButton[3][3];
    Font font = new Font("Verdana", Font.BOLD, 14);
    for (int y = 0; y < 3; y++) {
        for (int x = 0; x < 3; x++) {
            botoes[x][y] = new JButton();
            botoes[x][y].setActionCommand("b" + x + "_" + y);
            botoes[x][y].addActionListener(this);
            botoes[x][y].setFont(font);
            pJogo.add(botoes[x][y]);
        }
    }
    getContentPane().add(pJogo, BorderLayout.CENTER);
    getContentPane().validate();
    // Começa o X
    vez = "X";
    terminou = false;
}

public <botoes, botoes, botoes> void actionPerformed(ActionEvent arg0) {
    if ("Sair".equals(arg0.getActionCommand())) {
        if (JOptionPane.showConfirmDialog(null, "Deseja sair do jogo da velha?", "Sair", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
            System.exit(0);
        }
    } else if ("Novo Jogo".equals(arg0.getActionCommand())) {
        criarNovoJogo();
    } else if (arg0.getActionCommand().startsWith("b")) {
        if (terminou) {
            JOptionPane.showMessageDialog(null, "Jogo finalizado!", "Erro", JOptionPane.ERROR_MESSAGE);
        } else {
            String[] coord = arg0.getActionCommand().substring(1).split("_");
            int x = Integer.parseInt(coord[0]);
            int y = Integer.parseInt(coord[1]);
            if (botoes[x][y].getText().equals("")) {
                botoes[x][y].setText(vez);
                if (vez.equals("X")) {
                    botoes[x][y].setForeground(COR_X);                        
                    vez = "O";
                } else {
                    botoes[x][y].setForeground(COR_O);                        
                    vez = "X";
                }
                verificarVitoria();
            } else {
                JOptionPane.showMessageDialog(null, "Posição já foi marcada!", "Erro", JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}

private void verificarVitoria() {
    String vencedor = "";
    // Verifica horizontais e verticais
    for (int i = 0; i < 3; i++) {
        if (!botoes[i][0].getText().equals("")) {
            if ((botoes[i][0].getText().equals(botoes[i][1].getText())) && (botoes[i][2].getText().equals(botoes[i][1].getText()))) {
                terminou = true;
                vencedor = botoes[i][0].getText();
                break;
            }
        }
        if (!botoes[0][i].getText().equals("")) {
            if ((botoes[0][i].getText().equals(botoes[1][i].getText())) && (botoes[2][i].getText().equals(botoes[1][i].getText()))) {
                terminou = true;
                vencedor = botoes[0][i].getText();
                break;
            }
        }
    }
    // Verifica diagonais
    if (!botoes[1][1].getText().equals("")) {
        if ((botoes[0][0].getText().equals(botoes[1][1].getText())) && (botoes[2][2].getText().equals(botoes[1][1].getText()))) {
            terminou = true;
            vencedor = botoes[1][1].getText();
        } else if ((botoes[0][2].getText().equals(botoes[1][1].getText())) && (botoes[2][0].getText().equals(botoes[1][1].getText()))) {
            terminou = true;
            vencedor = botoes[1][1].getText();
        }
    }
    if (terminou) {
        JOptionPane.showMessageDialog(null, vencedor + " é o vencedor!", "Vitória", JOptionPane.INFORMATION_MESSAGE);
    }
}

public final void centralizarJanela() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    int x = ge.getCenterPoint().x - (this.getWidth() / 2);
    int y = ge.getCenterPoint().y - (this.getHeight() / 2);
    setLocation(x, y);
}
/**
 * @param args
 */
public static void main(String[] args) {
    JogoDaVelha jogo = new JogoDaVelha();
    jogo.setVisible(true);
}

}

http://www.guj.com.br/java/50115-voce-e-novo-no-guj-vai-criar-um-topico-e-colar-seu-codigo-fonte-leia-aqui-antes-por-favor

Ninguem responde minha dúvida…me ajudem ai galera…to passando maior aperto…pra saber por quais metodos devo subistituir…

vc nao leu o que eu postei…

como está fora dos padroes ninguem responde

vc nao posta o StackTrace…

aprenda a usar o forum antes de fazer uma pergunta

Bom dia Galera tenho esse codigo aqui em java correto?porme fui passar para android e como ainda nao tenho muito conehcimento nao consigo saber o que tenho q tirar para que pare de dar pau…lembrando q no android a interface é colocada separada do codigo java…

package com.jogoDaVelha;





//import java.awt.BorderLayout;
//import java.awt.Color;
//import java.awt.Font;
//import java.awt.GraphicsEnvironment;
//import java.awt.GridLayout;
//import java.awt.HeadlessException;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
//import java.awt.event.WindowAdapter;
//import java.awt.event.WindowEvent;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;


//import javax.swing.Box;
//import javax.swing.JButton;
//import javax.swing.JFrame;
//import javax.swing.JMenu;
//import javax.swing.JMenuBar;
//import javax.swing.JMenuItem;
//import javax.swing.JOptionPane;
//import javax.swing.JPanel;
//import javax.swing.WindowConstants;

public class JogoDaVelha extends Activity implements ActionListener {
private static final long serialVersionUID = 1L;
private JButton[][] botoes;
private String vez;
private boolean terminou;
private static final Color COR_X = Color.RED;
private static final Color COR_O = Color.BLUE;

public JogoDaVelha() throws HeadlessException {
super("Jogo da Velha");
// Define tamanho da janela
setSize(200, 240);
// Define menu
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Jogo");
JMenuItem iteNovo = new JMenuItem("Novo Jogo");
iteNovo.addActionListener(this);
menu.add(iteNovo);
menu.addSeparator();
JMenuItem iteSair = new JMenuItem("Sair");
iteSair.addActionListener(this);
menu.add(iteSair);
menuBar.add(menu);
setJMenuBar(menuBar);
// Panel com os botões
criarNovoJogo();
// Chama método para centralizar janela
centralizarJanela();
// Prepara saída da janela
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public final void windowClosing(final WindowEvent e) {
if (JOptionPane.showConfirmDialog(null, "Deseja fechar o jogo da velha?", "Fechar", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
System.exit(0);
}
}
});
}

private void criarNovoJogo() {
getContentPane().removeAll();
// Define layout da janela
int borda = 25;
getContentPane().setLayout(new BorderLayout());
getContentPane().add(Box.createVerticalStrut(borda), BorderLayout.NORTH);
getContentPane().add(Box.createVerticalStrut(borda), BorderLayout.SOUTH);
getContentPane().add(Box.createHorizontalStrut(borda), BorderLayout.EAST);
getContentPane().add(Box.createHorizontalStrut(borda), BorderLayout.WEST);
JPanel pJogo = new JPanel();
pJogo.setLayout(new GridLayout(3, 3));
// Cria conjunto de botões
botoes = new JButton[3][3];
Font font = new Font("Verdana", Font.BOLD, 14);
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
botoes[x][y] = new JButton();
botoes[x][y].setActionCommand("b" + x + "_" + y);
botoes[x][y].addActionListener(this);
botoes[x][y].setFont(font);
pJogo.add(botoes[x][y]);
}
}
getContentPane().add(pJogo, BorderLayout.CENTER);
getContentPane().validate();
// Começa o X
vez = "X";
terminou = false;
}

public <botoes, botoes, botoes> void actionPerformed(ActionEvent arg0) {
if ("Sair".equals(arg0.getActionCommand())) {
if (JOptionPane.showConfirmDialog(null, "Deseja sair do jogo da velha?", "Sair", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
System.exit(0);
}
} else if ("Novo Jogo".equals(arg0.getActionCommand())) {
criarNovoJogo();
} else if (arg0.getActionCommand().startsWith("b")) {
if (terminou) {
JOptionPane.showMessageDialog(null, "Jogo finalizado!", "Erro", JOptionPane.ERROR_MESSAGE);
} else {
String[] coord = arg0.getActionCommand().substring(1).split("_");
int x = Integer.parseInt(coord[0]);
int y = Integer.parseInt(coord[1]);
if (botoes[x][y].getText().equals("")) {
botoes[x][y].setText(vez);
if (vez.equals("X")) {
botoes[x][y].setForeground(COR_X);
vez = "O";
} else {
botoes[x][y].setForeground(COR_O);
vez = "X";
}
verificarVitoria();
} else {
JOptionPane.showMessageDialog(null, "Posição já foi marcada!", "Erro", JOptionPane.ERROR_MESSAGE);
}
}
}
}

private void verificarVitoria() {
String vencedor = "";
// Verifica horizontais e verticais
for (int i = 0; i < 3; i++) {
if (!botoes[i][0].getText().equals("")) {
if ((botoes[i][0].getText().equals(botoes[i][1].getText())) && (botoes[i][2].getText().equals(botoes[i][1].getText()))) {
terminou = true;
vencedor = botoes[i][0].getText();
break;
}
}
if (!botoes[0][i].getText().equals("")) {
if ((botoes[0][i].getText().equals(botoes[1][i].getText())) && (botoes[2][i].getText().equals(botoes[1][i].getText()))) {
terminou = true;
vencedor = botoes[0][i].getText();
break;
}
}
}
// Verifica diagonais
if (!botoes[1][1].getText().equals("")) {
if ((botoes[0][0].getText().equals(botoes[1][1].getText())) && (botoes[2][2].getText().equals(botoes[1][1].getText()))) {
terminou = true;
vencedor = botoes[1][1].getText();
} else if ((botoes[0][2].getText().equals(botoes[1][1].getText())) && (botoes[2][0].getText().equals(botoes[1][1].getText()))) {
terminou = true;
vencedor = botoes[1][1].getText();
}
}
if (terminou) {
JOptionPane.showMessageDialog(null, vencedor + " é o vencedor!", "Vitória", JOptionPane.INFORMATION_MESSAGE);
}
}

public final void centralizarJanela() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
int x = ge.getCenterPoint().x - (this.getWidth() / 2);
int y = ge.getCenterPoint().y - (this.getHeight() / 2);
setLocation(x, y);
}
/**
* @param args
*/
public static void main(String[] args) {
JogoDaVelha jogo = new JogoDaVelha();
jogo.setVisible(true);
}
} 

erros?

posta o StackTrace não somos adivinhos

Este codigo esta correto porem na linguagem android a interface é feito separadamente,porém não tenho habilidade para saber o que substituo para nao dar erro no codigo(coloca esse código no eclipse porém tem que ter o SDK do android instalado )e verifica os erros que irão aparecer.

Agora não precisa ser mal educado com suas respostas.Se não for possivel ,mesmo assim fico agradecido.

Voce tem que mudar de paradigma quando vai programar para Android, não é tão simples assim simplesmente ‘traduzir’ o código entre as plataformas, e a solução mais fácil normalmente é reescrever tudo do zero.

Eu ando psotando alguns artigos sobre Android para iniciantes e voce pode ver aqui:

Pelo menos voce vai entender como é feita uma aplicação para Android.

Obrigadão cara…mas já tenho o codigo em java…não tem um caminho para isso não?substituir os metodos do swing por algum semelhante do android?

Gostaria de ter um como base para que possa substitur este daqui.

A Marky já te respondeu que não é substituição e você insiste com isto.

Já obteve a resposta que precisava, agora foque em comprar um livro de Android, estudar e daí após ter aprendido o básico, portar sua aplicação para j2me.

Se continuar insistindo com o assunto vamos entender que propositalmente está querendo encher o saco dos outros o que denota uma das práticas de um verdadeiro troll.

Estou olhando aqui seu blog,porém não estou entendendo muito bem…tem como você colocar este códgio acima no ecplise e olhar o que tenho que alterar para que ele rode …Sei que tenho q fazer a interface também senão nunca vai rodar …Mas esta parte do .java tem como ficar redondo sem a interface?

eu nao li isso ne??
[ironic mode on]

acho que eu to drogado, por que parece que eu li que vc ta querendo que o pessoal aqui faça o codigo pra vc (colocar no eclipse e corrigir os erros pra vc)

eu devo ta drogado mesmo, porque nem um ser é tão folgado a esse ponto… [ironic mode off]

Basicamente, todo seu código vai mudar. A interface inteira é montada de um modo diferente.

Para voce começar voce pode ver como prepara o ambiente.

Depois como criar sua atividade:

E depois disse se voce souber qual é a sua duvida, volte aqui que ficaremos feliz em ajudar.