elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


  Mostrar Temas
Páginas: [1]
1  Programación / Java / Problema Java en: 14 Junio 2014, 09:52 am
Hola buenas, estoy haciendo un chat en java, pero tengo un problema, los mensajes solo se le muestran al usuario que se les manda, estoy usando javascript en el cliente y java en el servidor. Estoy enviando los datos al cliente por session, pero no consigo que se le manden a todos los usuarios.
2  Programación / Java / Duda con java y struts en: 12 Marzo 2014, 22:56 pm
Hola buenas tengo una duda con Struts 2, vereis quiero mostrar los platos de un restaurante en una jsp, pero me he quedado un poco perdido.
Tengo esta jsp
Código:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="es">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title></title>
        <link href="css/bootstrap.css" rel="stylesheet">
        <link href="css/business-casual.css" rel="stylesheet">
    </head>
    <body>
        <ul class="nav navbar-nav">
            <li><a href="index.jsp">Inicio</a></li>
            <li><a href="restaurante.jsp">Restaurantes</a></li>
            <li><a href="menu.jsp">Menus</a></li>
            <li><a href="plato.jsp">Platos</a></li>
            <li><a href="login.jsp">Login</a></li>
        </ul>
    </body>
</html>
Que llama a este action
Código:
package actions;

import com.opensymphony.xwork2.ActionSupport;

import dao.FactoriaDAO;
import dao.PlatoDAO;
@SuppressWarnings("serial")
public class AccionObtenerPlatoCategoria extends ActionSupport{
    private int idPlato;
    private String nombre;
    private String descripcion;
    private String Categoria;
   
    public int getIdPlato() {
        return idPlato;
    }

    public void setIdPlato(int idPlato) {
        this.idPlato = idPlato;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public String getCategoria() {
        return Categoria;
    }

    public void setCategoria(String categoria) {
        Categoria = categoria;
    }

    public String execute(){
        try{
            PlatoDAO plato = (PlatoDAO) FactoriaDAO.getInterfacePlatoDAO();
            plato.obtenerplato();
            return SUCCESS;
        }
        catch (Exception e) {
            return ERROR;
        }
    }
}
Y de alli llamo a un DAO que es el que obtiene los datos
Código:
package dao;

import java.sql.ResultSet;
import java.util.ArrayList;

import beans.Plato;
import db.DBFacade;

public class PlatoDAO implements InterfacePlatoDAO{
    private DBFacade db = null;
    public PlatoDAO() throws Exception{
        try{
            db = new DBFacade();
        }
        catch (Exception e) {       
            throw new Exception(e);
        }
    }
    /**
     *
     */
    public ArrayList<Plato> obtenerplato() throws Exception{
        ResultSet consul = null;
        ArrayList<Plato>  plato = new ArrayList<Plato>();
        try {
            db.abrirConexion();
            String query = "select * from plato";
            consul = db.ejecutarConsulta(query);
            while(consul.next()){
                Plato plat = new Plato();
                plat.setIdPlato(consul.getInt("idPlato"));
                plat.setNombre(consul.getString("nombre"));
                plat.setDescripcion(consul.getString("descripcion"));
                plat.setCategoria(consul.getString("Categoria"));
                plato.add(plat);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally{
            try{
                db.cerrarConexion();
            }
            catch (Exception e1) {
                throw new Exception(e1);
            }
        }
        return plato;
    }
    /**
     *
     */
    public ArrayList<Plato> obtenerplatocategoria(Plato plato) throws Exception{
        ResultSet consul = null;
        ArrayList<Plato>  platos = new ArrayList<Plato>();
        try {
            db.abrirConexion();
            String Categoria = plato.getCategoria();
            String query = "select * from plato where categoria=="+Categoria;
            consul = db.ejecutarConsulta(query);
            while(consul.next()){
                Plato plat = new Plato();
                plat.setIdPlato(consul.getInt("idPlato"));
                plat.setNombre(consul.getString("nombre"));
                plat.setDescripcion(consul.getString("descripcion"));
                plat.setCategoria(consul.getString("Categoria"));
                platos.add(plat);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally{
            try{
                db.cerrarConexion();
            }
            catch (Exception e1) {
                throw new Exception(e1);
            }
        }
        return platos;
    }
}
Los datos los obtiene de la base de datos pero me he quedado un poco perdido sobre como mostrarlos en la JSP.
3  Programación / Java / Ayuda conecta4 en: 16 Junio 2013, 17:56 pm
Hola buenas estoy acabando el conecta4 y por ahora me funciona correctamente, pero el equipo es un numero aleatorio y queria que tuviera la posibilidad de ganar, me podrian explicar alguna manera sencilla, este es mi codigo:
import java.awt.*;
import javax.swing.ImageIcon;
public class cuatroenraya extends javax.swing.JFrame {
    public cuatroenraya() {
        initComponents();
        getContentPane().setBackground(Color.black);
        this.jTextField1.setVisible(false);
        this.jButton4.setVisible(false);
        this.jTextField2.setVisible(false);
        this.jButton5.setVisible(false);
        this.jButton6.setVisible(false);
    }
    static int vector[] = new int [7];
    static int tablero[][] = new int[6][7];
    int turnoj1=1;
    int turnoj2=1;
    boolean finpartida;
    boolean numjug;
    public static void inicializotablero()
    {
        for(int i=0;i<6;i++)
        {
            for (int j=0;j<7;j++)
            {
                tablero[j]=0;
            }
        }
        for(int i=0;i<7;i++)
        {
            vector=0;
        }
    }
    void movimientomaquina()
    {
         for(int i=0;i<6;i++)
        {
            for (int j=0;j<7;j++)
            {
                if(tablero[j]!=1)
                {
                    if(tablero[j+1]!=1)
                    {
                        if(tablero[j+2]!=1)
                        {
                           
                        }
                    }
                }
            }
        }
    }
    public static boolean ganadora()
    { 
        boolean gan=false;
        for(int i=0;i<6;i++)
        {
            for(int j=0;j<7;j++)
            {
                ganar(i,j);
                if(ganar(i,j)==true)
                {
                   gan=true;
                }
            }
        }
        return gan;
    }
    public static void menu() throws Exception
    {
        inicializotablero();
    }
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        ImageIcon fondo = new ImageIcon(new ImageIcon(getClass().getResource("fondo.jpg")).getImage());
        g.drawImage(fondo.getImage(), -150, 0, null);
        dibujartablero(g);
       
    }
    void comprobarganadormj()
    {
        if(ganadora()==true)
        {
            if(turnoj1==turnoj2)
            {
                this.jLabel1.setText("Gana el jugador 2");
                this.jButton4.setVisible(false);
                this.jButton5.setVisible(false);
                this.jButton6.setVisible(false);
                this.jTextField1.setVisible(false);
                this.jTextField2.setVisible(false);
            }
            if(turnoj1>turnoj2)
            {
                this.jLabel1.setText("Gana el jugador 1");
                this.jButton4.setVisible(false);
                this.jButton5.setVisible(false);
                this.jButton6.setVisible(false);
                this.jTextField1.setVisible(false);
                this.jTextField2.setVisible(false);
            }
        }
    }
    public void comprobarganadorj()
    {
        if(ganadora()==true)
        {
            if(turnoj1==turnoj2)
            {
                this.jLabel1.setText("Gana el jugador 2");
                this.jButton4.setVisible(false);
                this.jButton5.setVisible(false);
                this.jButton6.setVisible(false);
                this.jTextField1.setVisible(false);
                this.jTextField2.setVisible(false);
            }
            if(turnoj1>turnoj2)
            {
                this.jLabel1.setText("Gana el jugador 1");
                this.jButton4.setVisible(false);
                this.jButton5.setVisible(false);
                this.jButton6.setVisible(false);
                this.jTextField1.setVisible(false);
                this.jTextField2.setVisible(false);
            }
        }
    }
    void dibujartablero(Graphics g)
    {
        ImageIcon fichablanco = new ImageIcon(new ImageIcon(getClass().getResource("fichagris.png")).getImage());
        ImageIcon ficharoja = new ImageIcon(new ImageIcon(getClass().getResource("ficharoja.png")).getImage());
        ImageIcon fichanegra = new ImageIcon(new ImageIcon(getClass().getResource("fichanegra.png")).getImage());
        int x=150;
        int y=150;
        for(int i=0;i<6;i++)
        {
            for(int j=0;j<7;j++)
            {
                if(tablero[j]==0)
                {
                    g.drawImage(fichablanco.getImage(), x, y, null);
                    x=x+100;
                    if (j==tablero.length-1)
                    {
                        x=150;
                        y=y+80;
                    }
                }
                if(tablero[j]==1)
                {
                    g.drawImage(ficharoja.getImage(), x, y, null);
                    x=x+100;
                    if (j==tablero.length-1)
                    {
                        x=150;
                        y=y+80;
                    }
                }
                if(tablero[j]==2)
                {
                    g.drawImage(fichanegra.getImage(), x, y, null);
                    x=x+100;
                    if (j==tablero.length-1)
                    {
                        x=150;
                        y=y+80;
                    }
                }
            }
        }
    }
    public void unjugador()
    {
        if(turnoj1==turnoj2)
        {
            this.jLabel1.setText("");
            String text;
            int n;
            text=jTextField1.getText();
            n=Integer.parseInt(text);
            n=n-1;
            tablero[5-vector[n]][n]=1;
            vector[n]++;
            turnoj1++;
            comprobarganadorj();
            repaint();
        }
        if(turnoj1-1==turnoj2)
        {
            movimientomaquina();
            turnoj2++;
            comprobarganadorj();
            repaint();
        }
    }
    public void multijugadorj1()
    {
        this.jLabel1.setText("");
        if(turnoj1==turnoj2)
        {
            if(!ganadora())
            {
                String textj1;
                int j1;
                textj1=jTextField1.getText();
                j1=Integer.parseInt(textj1);
                j1=j1-1;
                tablero[5-vector[j1]][j1]=1;
                vector[j1]++;
                jTextField1.setText("");
                turnoj1++;
                comprobarganadormj();
                repaint();
            }
        }
        else
        {
            this.jLabel1.setText("No es tu turno");
        }
    }
    public void multijugadorj2()
    {
        this.jLabel1.setText("");
        if(turnoj1-1==turnoj2)
        {
            String textj2;
            int j2;
            textj2=jTextField2.getText();
            j2=Integer.parseInt(textj2);
            j2=j2-1;
            tablero[5-vector[j2]][j2]=2;
            vector[j2]++;
            jTextField2.setText("");
            turnoj2++;
            comprobarganadormj();
            repaint();
        }
        else
        {
            this.jLabel1.setText("No es tu turno");
        }
    }
    static boolean ganar(int i, int j)
    {
        boolean juggan;
        if(derecha(i,j))
        {
            juggan=true;
        }
        else if(diagonalderecha(i,j))
        {
            juggan=true;
        }
        else if(diagonalizquierda(i,j))
        {
            juggan=true;
        }
        else if(abajo(i,j))
        {
            juggan=true;
        }
        else
        {
            juggan=false;
        }
        return juggan;
    }
    static boolean derecha (int i, int j)
    {
        boolean retorno;
        if(j<3)
        {
        if(tablero[j]==tablero[j+1] && tablero[j]!=0)
        {
            if(tablero[j]==tablero[j+2] && tablero[j]!=0)
            {
                if(tablero[j]==tablero[j+3] && tablero[j]!=0)
                {
                    retorno=true;
                }
                else
                {
                    retorno=false;
                }
            }
            else
            {
                retorno=false;
            } 
        }
        else
        {
            retorno=false;
        }
        }
        else
        {
            retorno=false;
        }
        return retorno;
    }
    static boolean diagonalderecha (int i, int j)
    { boolean retorno;
        if(i<=2 && j<=3)
        {
        if(tablero[j]==tablero[i+1][j+1] && tablero[j]!=0)
        {
            if(tablero[j]==tablero[i+2][j+2])
            {
                if(tablero[j]==tablero[i+3][j+3])
                {
                    retorno=true;
                }
                else
                {
                    retorno=false;
                }
            }
            else
            {
                retorno=false;
            }
        }
        else
        {
            retorno=false;
        }
        }
        else
        {
            retorno=false;
           
        }
        return retorno;
    }   
    static boolean abajo(int i, int j)
    {
        boolean retorno;
        if(i<=2)
        {
        if(tablero[j]==tablero[i+1][j] && tablero[j]!=0)
        {
            if(tablero[j]==tablero[i+2][j] && tablero[j]!=0)
            {
                if(tablero[j]==tablero[i+3][j] && tablero[j]!=0)
                {
                    retorno=true;
                }
                else
                {
                    retorno=false;
                }
            }
            else
            {
                retorno=false;
            } 
        }
        else
        {
            retorno=false;
        }
        }
        else
        {
            retorno=false;
        }
        return retorno;
    }
    static boolean diagonalizquierda (int i, int j)
    {
        boolean retorno;
        if(i<=2 && j>2)
        {
            if(tablero[j]==tablero[i+1][j-1] && tablero[j]!=0)
            {
                if(tablero[j]==tablero[i+2][j-2])
                {
                    if(tablero[j]==tablero[i+3][j-3])
                    {
                        retorno=true;
                    }   
                    else
                    {
                        retorno=false;
                    }
                }
                else
                {
                    retorno=false;
                }
            }
            else
            {
                retorno=false;
            }
        }
        else
        {
            retorno=false;
        }
        return retorno;
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(0, 0, 0));

        jButton1.setText("Un Jugador");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Multijugador");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Salir");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Enviar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Enviar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("Enviar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(204, 0, 0));

        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(871, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jButton4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE))
                            .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(17, 17, 17))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton5)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(60, 60, 60)
                                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(33, 33, 33))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(81, 81, 81)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton5)
                .addGap(35, 35, 35)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(268, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                       

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        System.exit(0);
    }                                       

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        this.jButton4.setVisible(false);
        this.jTextField2.setVisible(true);
        this.jButton5.setVisible(true);
        this.jTextField1.setVisible(true);
        this.jButton6.setVisible(true);
        inicializotablero();
        this.jTextField1.setText("");
        this.jTextField2.setText("");
        repaint();
    }                                       

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        this.jTextField1.setVisible(true);
        this.jButton4.setVisible(true);
        this.jTextField2.setVisible(false);
        this.jButton5.setVisible(false);
        this.jButton6.setVisible(false);
        inicializotablero();
        this.jTextField1.setText("");
        this.jTextField2.setText("");
        repaint();
    }                                       

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
               unjugador(); 
    }                                       

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        multijugadorj2();
    }                                       

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        multijugadorj1();
    }                                       

    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(cuatroenraya.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(cuatroenraya.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(cuatroenraya.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(cuatroenraya.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 cuatroenraya().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration                   
}
4  Programación / Java / Novato ayuda con programa sencillo en java en: 12 Febrero 2013, 00:02 am
Hola buenas necesito ayuda con un programa ya que llevo tiempo dandole vueltas pero no lo consigo tengo el siguiente codigo:
package ej81;

import java.util.Scanner;


public class Ej81 {
    static   int [][] m= new int[10][10];
    static int SolicitoDatos()
    {
        int fc;
        fc=10;
        return fc;
    }
    static void rellenoMatriz ()
    {
        int i,j;
        for (i=0;i<10;i++)
        {
            for (j=0;j<10;j++)
            {
              if (i==j)
              {
              m[j]=1;
              }
              else
                  m[j]=0;
            } 
        }
    }
    static void escriboMatriz(int fc)
    {
        int alc;
        int alf;
        alc = (int) (Math.random()*10);
        alf = (int) (Math.random()*10);
        for(int i=0;i<10;i++)
        {
            for(int j=0;j<10;j++)
            {
                System.out.print(0);
               
            }
            System.out.println();
        }
    }
    public static void main(String[] args) {
        int b;
        b=SolicitoDatos();
        rellenoMatriz();
        escriboMatriz(b);
    }
}
que lo que hace es imprimir todo ceros pero necesito que me imprima tambien 0 de manera que quedara parecido a esto como si fuera el juego de los barcos:
000011110
000000000
100010001
000000000
000100011
000000000
000000110
111000000
000000110
000111000
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines