[b]Oi galera sou novo no forum e na area de programação e estou precisando de ajuda estou fazendo um simulador do campeonato brasileiro só que estou com dificuldades para tratar alguns eventos na pagina da rodada. desde já agradeço
package persistencia;
/**
*
-
@author User
*/
import java.sql.SQLException;
import java.util.Vector;
public class AuxiliarRodada {
static int i=1;
public void AuxiliarRodada()
{
}
public static void percorrer(String direcao, Vector<Rodada> r) throws SQLException
{
if ("Anterior".equals(direcao) && i > 1){
i--;
}else if ("Proximo".equals(direcao)){
i++;
}
new TimeDAO().consultarRodada(r, i);
}
}
package persistencia;
import java.sql.*;
/**
*
-
@author root
*/
public class FabricaDeConexoes {/** Creates a new instance of FabricaDeConexoes */ public FabricaDeConexoes() { }
public static Connection getConexao() throws SQLException { String driver = “sun.jdbc.odbc.JdbcOdbcDriver”; //access String url = “jdbc:odbc:brasileiro”; //endereco do banco de dados // try catch try { Class.forName(driver); return DriverManager.getConnection(url); } catch (ClassNotFoundException e) { throw new SQLException(); } } }
package persistencia;
/**
*
-
@author User
*/
import java.util.Date;
public class Rodada {
private String timeA;
private int timeACodigo;
private String timeB;
private int timeBCodigo;
private int rodada;
private Date data;
public int getTimeACodigo() {
return timeACodigo;
}
public void setTimeACodigo(int timeACodigo) {
this.timeACodigo = timeACodigo;
}
public int getTimeBCodigo() {
return timeBCodigo;
}
public void setTimeBCodigo(int timeBCodigo) {
this.timeBCodigo = timeBCodigo;
}
public Rodada(int rodada, Date data, String timeA, String timeB, int timeACodigo, int timeBCodigo)
{
this.timeA = timeA;
this.timeACodigo = timeACodigo;
this.timeB = timeB;
this.timeBCodigo = timeBCodigo;
this.rodada = rodada;
this.data = data;
}
/**
* @return the timeA
*/
public String getTimeA() {
return timeA;
}
/**
* @param timeA the timeA to set
*/
public void setTimeA(String timeA) {
this.timeA = timeA;
}
/**
* @return the timeB
*/
public String getTimeB() {
return timeB;
}
/**
* @param timeB the timeB to set
*/
public void setTimeB(String timeB) {
this.timeB = timeB;
}
/**
* @return the rodada
*/
public int getRodada() {
return rodada;
}
/**
* @param rodada the rodada to set
*/
public void setRodada(int rodada) {
this.rodada = rodada;
}
/**
* @return the data
*/
public Date getData() {
return data;
}
/**
* @param data the data to set
*/
public void setData(Date data) {
this.data = data;
}
}
package persistencia;
/**
*
-
@author User */ import java.sql.SQLException; import java.util.Vector; public class Simulador {
private static int gol1; private static int gol2; private static int timeA; private static int timeB; private static Vector t;
public Simulador() { gol1 = -1; gol2 = -1; t = new Vector(); }
public int getTimeA() { return timeA; }
public static void setTimeA(int time) { timeA = time; }
public int getTimeB() { return timeB; }
public static void setTimeB(int time) { timeB = time; }
public int getGol1() { return gol1; }
public void setGol1(int gol) { gol1 = gol; }
public int getGol2() { return gol2; }
public void setGol2(int gol) { gol2 = gol; }
public static void simular()throws SQLException { if (gol1 != -1 && gol2 != -1) { if (gol1 > gol2) { // Time(codigo, nome, ponto, 0, vitoria, empate, derrota, golPro, golContra, 0, 0) t.add(new Time( timeA, “s”, 3, 0, 1, 0, 0, gol1, gol2, 0, 0)); t.add(new Time( timeB, “s”, 0, 0, 0, 0, 1, gol2, gol1, 0, 0)); }else if (gol1 < gol2) { // Time(codigo, nome, ponto, 0, vitoria, empate, derrota, golPro, golContra, 0, 0) t.add(new Time( timeA, “s”, 0, 0, 0, 0, 1, gol1, gol2, 0, 0)); t.add(new Time( timeB, “s”, 3, 0, 1, 0, 0, gol2, gol1, 0, 0)); }else { // Time(codigo, nome, ponto, 0, vitoria, empate, derrota, golPro, golContra, 0, 0) t.add(new Time( timeA, “s”, 1, 0, 0, 1, 0, gol1, gol2, 0, 0)); t.add(new Time( timeB, “s”, 1, 0, 0, 1, 0, gol2, gol1, 0, 0)); } new TimeDAO().atualizarTime(t); } } }
package persistencia;
/**
*
-
@author User
*/
public class Time {private int codigo; private String nome; private int ponto; private int jogo; private int vitoria; private int empate; private int derrota; private int golPro; private int golContra; private int saldoGol; private int porcentagem;
public Time(int codigo, String nome, int ponto, int jogo, int vitoria, int empate, int derrota, int golPro, int golContra, int saldoGol, int porcentagem) { this.codigo = codigo; this.nome = nome; this.ponto = ponto; this.jogo = jogo; this.vitoria = vitoria; this.empate = empate; this.derrota = derrota; this.golPro = golPro; this.golContra = golContra; this.saldoGol = saldoGol; this.porcentagem = porcentagem;
}
/**-
@return the nome
*/
public String getNome() {
return nome;
}
/**
-
@return the ponto
*/
public int getPonto() {
return ponto;
}
/**
-
@param ponto the ponto to set
*/
public void setPonto(int ponto) {
this.ponto = ponto;
}
/**
-
@return the jogo
*/
public int getJogo() {
return jogo;
}
/**
-
@param jogo the jogo to set
*/
public void setJogo(int jogo) {
this.jogo = jogo;
}
/**
-
@return the vitoria
*/
public int getVitoria() {
return vitoria;
}
/**
-
@param vitoria the vitoria to set
*/
public void setVitoria(int vitoria) {
this.vitoria = vitoria;
}
/**
-
@return the empate
*/
public int getEmpate() {
return empate;
}
/**
-
@param empate the empate to set
*/
public void setEmpate(int empate) {
this.empate = empate;
}
/**
-
@return the derrota
*/
public int getDerrota() {
return derrota;
}
/**
-
@param derrota the derrota to set
*/
public void setDerrota(int derrota) {
this.derrota = derrota;
}
/**
-
@return the golPos
*/
public int getGolPro() {
return golPro;
}
/**
-
@param golPos the golPos to set
*/
public void setGolPro(int golPro) {
this.golPro = golPro;
}
/**
-
@return the golContra
*/
public int getGolContra() {
return golContra;
}
/**
-
@param golContra the golContra to set
*/
public void setGolContra(int golContra) {
this.golContra = golContra;
}
/**
-
@return the saldoGol
*/
public int getSaldoGol() {
return saldoGol;
}
/**
-
@param saldoGol the saldoGol to set
*/
public void setSaldoGol(int saldoGol) {
this.saldoGol = saldoGol;
}
/**
-
@return the porcentagem
*/
public int getPorcentagem() {
return porcentagem;
}
/**
-
@param porcentagem the porcentagem to set
*/
public void setPorcentagem(int porcentagem) {
this.porcentagem = porcentagem;
}
/**
-
@return the codigo
*/
public int getCodigo() {
return codigo;
}
/**
-
@param codigo the codigo to set
*/
public void setCodigo(int codigo) {
this.codigo = codigo;
}
/**
-
@param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
-
@return the nome
}
package persistencia;
import java.sql.*;
import java.util.Vector;
/**
*
-
@author Administrador
*/
public class TimeDAO {private Connection conexao;
/** Creates a new instance of PessoaDAO */ public TimeDAO() throws SQLException { this.conexao = FabricaDeConexoes.getConexao(); }
public void cadastrarTime(Time t) { String cadastro = “”;
try { PreparedStatement ps = conexao.prepareStatement(cadastro); //primeiro parametro corresponde as interrogações ps.setInt(1,t.getCodigo()); ps.execute(); ps.close(); conexao.close(); } catch(SQLException e) { }
}
public void consultarTime(Vector<Time> t) { String consulta = "SELECT TIME_DS, TABR_PONTO_NR, TABR_JOGO_NR, TABR_VITO_NR, TABR_EMPA_NR, TABR_DERR_NR, TABR_PRO_GOL_NR, TABR_CONT_GOL_NR, TABR_GOL_SALD_NR, TABR_PORC_NR FROM TABE_BRAS INNER JOIN [TIME] ON TIME.TIME_ID = TABE_BRAS.TABR_TIME_ID ORDER BY TABR_PRO_GOL_NR DESC, TABR_GOL_SALD_NR DESC, TABR_VITO_NR DESC, TABR_PONTO_NR DESC;"; try { PreparedStatement ps = conexao.prepareStatement(consulta); ResultSet rs = ps.executeQuery(); while (rs.next()){ t.add(new Time(0, rs.getString("TIME_DS"), rs.getInt("TABR_PONTO_NR"), rs.getInt("TABR_JOGO_NR"), rs.getInt("TABR_VITO_NR"), rs.getInt("TABR_EMPA_NR"), rs.getInt("TABR_DERR_NR"), rs.getInt("TABR_PRO_GOL_NR"), rs.getInt("TABR_CONT_GOL_NR"), rs.getInt("TABR_GOL_SALD_NR"), rs.getInt("TABR_PORC_NR"))); } rs.close(); ps.close(); conexao.close(); } catch(SQLException e) { } } public void consultarRodada(Vector<Rodada> r, int id) { String consulta = "SELECT RODA_NR, RODA_DT, T1.TIME_DS, T2.TIME_DS, RODA_TIME_A_ID, RODA_TIME_B_ID FROM RODADA,[TIME] T1, [TIME] T2 WHERE T1.TIME_ID=RODADA.RODA_TIME_A_ID AND T2.TIME_ID=RODADA.RODA_TIME_B_ID AND RODA_NR=?;"; try { PreparedStatement ps = conexao.prepareStatement(consulta); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); while (rs.next()){ r.add(new Rodada(rs.getInt(1),rs.getDate(2),rs.getString(3),rs.getString(4), rs.getInt(5), rs.getInt(6))); } rs.close(); ps.close(); conexao.close(); } catch(SQLException e) { } } public void atualizarTime(Vector<Time> t) { String atualizar = "UPDATE TABE_BRAS SET TABR_PONTO_NR=TABR_PONTO_NR + ?, TABR_JOGO_NR=TABR_JOGO_NR + ?, TABR_VITO_NR= TABR_VITO_NR + ?, TABR_EMPA_NR=TABR_EMPA_NR + ?, TABR_DERR_NR = TABR_DERR_NR + ?, TABR_PRO_GOL_NR=TABR_PRO_GOL_NR + ?, TABR_CONT_GOL_NR=TABR_CONT_GOL_NR + ?, TABR_GOL_SALD_NR=((TABR_PRO_GOL_NR +?) - (TABR_CONT_GOL_NR + ?)), TABR_PORC_NR=(((TABR_PONTO_NR + ?) * 100) / ((TABR_JOGO_NR + ?) * 3)) WHERE TABR_TIME_ID=?"; try { PreparedStatement ps = conexao.prepareStatement(atualizar); for (int i = 0;i < t.size(); i++){ //primeiro parametro corresponde as interrogações ps.setInt(1, t.elementAt(i).getPonto()); ps.setInt(2,1); ps.setInt(3,t.elementAt(i).getVitoria()); ps.setInt(4,t.elementAt(i).getEmpate()); ps.setInt(5,t.elementAt(i).getDerrota()); ps.setInt(6,t.elementAt(i).getGolPro()); ps.setInt(7,t.elementAt(i).getGolContra()); ps.setInt(8,t.elementAt(i).getGolPro()); ps.setInt(9,t.elementAt(i).getGolContra()); ps.setInt(10,t.elementAt(i).getPonto()); ps.setInt(11,1); ps.setInt(12,t.elementAt(i).getCodigo()); ps.execute(); } ps.close(); conexao.close(); } catch(SQLException e) { } } public void removerTime(Time t) { String remover = ""; try { PreparedStatement ps = conexao.prepareStatement(remover); //primeiro parametro corresponde as interrogações ps.setInt(1, t.getCodigo()); ps.execute(); ps.close(); conexao.close(); } catch(SQLException e) { } }
}