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

 

 


Tema destacado: Curso de javascript por TickTack


  Mostrar Mensajes
Páginas: [1]
1  Programación / Java / Re: obtener datos de una lista? en: 8 Agosto 2016, 18:09 pm
Debes utilizar un for para recorrerlo

int size=al.size();

for(int x=0;x<al.size();x++) {
  System.out.println(al.get(x));
}
2  Programación / Java / Re: Llenar una ventana con los datos de otra al abrirla en: 8 Agosto 2016, 17:59 pm
Lo primero es poner un método setText(String texto) a ventana2.
public class Ventana2 extends JDialog
{
   private JLabel etiqueta = new JLabel ("su texto aquí");
   ...
   public void setText (String elTexto)
   {
      etiqueta.setText(elTexto);
   }
}

Si Ventana1 es la que hace el new de Ventana2, simplemente tendremos llamar al método setText()

public class Ventana1 extends JDialog
{
   private Ventana2 v2 = new Ventana2();
   private JButton boton = new JButton("Pulsame");
   ...
   public Ventana1()
   {
      boton.addActionListener (new ActionListener() {
         public void actionPerformed (ActionEvent e) {
            v2.setText("El texto");
         }
      });
   }
}
3  Programación / Java / Re: Insertar registros en BD en: 8 Agosto 2016, 17:49 pm
Pues no se si te sirva pero aqui esta un ejemplo de insertar

public void insertarDatos(int rut,String nombre,String direccion,int fono){
this.rut=rut;
this.nombre=nombre;
this.direccion=direccion;
this.fono=fono;
System.out.println("Ingresando datos de la interfaz: " +rut+" "+nombre+" "+direccion+" "+fono);
Conexion conec = new Conexion();
try{
objConexion=conec.abrirConeccionBd(usuario, clave);
String sql = "INSERT INTO CLIENTE VALUES("+rut+",'"+nombre+"','"+direccion+"',"+fono +")";
conec.ejecutarTransaccion(sql, objConexion);
try{
System.out.println("Transaccion realizada al cliente");
}catch(Exception e){

}
}catch(Exception e){}
}
4  Programación / Java / Re: Duda con conectar mi base de datos en netbeans en: 5 Agosto 2016, 06:38 am
Un ejemplo de eso es
Código
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7.  
  8. public Connection getConexion()
  9. {
  10.   return conexion;
  11. }
  12.  
  13. public boolean crearConexion()
  14. {
  15.   try {
  16.      Class.forName("com.mysql.jdbc.Driver");
  17.      conexion = DriverManager.getConnection("jdbc:mysql://host:puerto/baseDatos","usuario","contraseña");
  18.   } catch (SQLException ex) {
  19.      ex.printStackTrace();
  20.      return false;
  21.   } catch (ClassNotFoundException ex) {
  22.      ex.printStackTrace();
  23.      return false;
  24.   }
  25.  
  26.   return true;
  27. }
  28.  
  29. public boolean ejecutarSQL(String sql)
  30. {
  31.   try {
  32.      Statement sentencia = conexion.createStatement();
  33.      sentencia.executeUpdate(sql);
  34.   } catch (SQLException ex) {
  35.      ex.printStackTrace();
  36.   return false;
  37.   }
  38.  
  39.   return true;
  40. }
  41.  
  42. public ResultSet ejecutarSQLSelect(String sql)
  43. {
  44.   ResultSet resultado;
  45.   try {
  46.      Statement sentencia = conexion.createStatement();
  47.      resultado = sentencia.executeQuery(sql);
  48.   } catch (SQLException ex) {
  49.      ex.printStackTrace();
  50.      return
null;
   }

   return resultado;
}


Mod: Los códigos deben ir en etiquetas GeSHi
5  Programación / Java / Re: Habilitar textfield con radiobutton en: 5 Agosto 2016, 06:34 am
Pues no se si te ayude pero podrías intentarlo así
Código
  1. public class Program {
  2.    //GUI code
  3.    JRadioButton b = new JRadioButton("Show");
  4.    b.addActionListener(new ShowListener);
  5.    public class ShowListener implements ActionListener {
  6.        public void actionPerformed(ActionEvent e) {
  7.            field.setEnabled(true);
  8.        }
  9.    }
  10. }
  11.  
  12.  


Mod: Los códigos deben ir en etiquetas GeSHi
6  Programación / Java / Re: como modificar Jtable en: 5 Agosto 2016, 06:28 am
Hola pues un ejemplo que tengo que te podría ayudar seria
Código
  1. int n=ps.executeUpdate();
  2. if(n>0)
  3. JOptionPane.showMessageDialog(null, "datos guardados");
  4. }catch(Exception e){
  5.    JOptionPane.showMessageDialog(null, "error"+ e.getMessage());
  6. }
  7. Llenar();
  8. Limpiar();
  9.    }                                          
  10.  
  11.    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {                                        
  12. Limpiar();
  13. Habilitar();
  14.        // TODO add your handling code here:
  15.    }
  16.  private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {                                    
  17. if(evt.getButton()==1){
  18.   try{
  19.       Habilitar();
  20.        int fila=jTable1.getSelectedRow();
  21.        String sql="select * from contactos where id="+jTable1.getValueAt(fila,0);
  22.        sent=Conn.createStatement();
  23.        ResultSet rs=sent.executeQuery(sql);
  24.        rs.next();
  25.        txtNombre.setText(rs.getString("nombre"));
  26.        txtDireccion.setText(rs.getString("direccion"));
  27.        txtTelefono.setText(rs.getString("telefono"));
  28.        txtCorreo.setText(rs.getString("correo"));
  29.  
  30. }catch(Exception e){
  31.    e.printStackTrace();
  32. }
  33.    }
  34.    }    
   


Mod: Los códigos deben ir en etiquetas GeSHi
7  Programación / Java / Re: Palindromo en: 9 Junio 2016, 20:54 pm
Bueno una forma de hacerlo seria utilizando un método recursivo espero te sirva lo siguiente

Código
  1. /**
  2.  *
  3.  * @author DIANA
  4.  */
  5. public class Palindromo {
  6.  
  7.    public static boolean esPalindromo(String palabra) {
  8.        return esPalindromo(palabra, 0, palabra.length() - 1);
  9.    }
  10.  
  11.    private static boolean esPalindromo(String palabra, int ini, int fin) {
  12.        if (fin - ini + 1 == 0 || fin - ini + 1 == 1) {
  13.            return true;
  14.        } else {
  15.            if (palabra.charAt(ini) == palabra.charAt(fin)) {
  16.                return esPalindromo(palabra, ini + 1, fin - 1);
  17.            } else {
  18.                return false;
  19.            }
  20.        }
  21.    }
  22. }
  23.  


8  Programación / Java / Re: Resgitro de datos desde un jtable en java netbeans a base de datos mysql en: 9 Junio 2016, 20:34 pm
Bueno Larry16 sin tu codigo no sabria responderte bien pero el codigo que podrias utilizar para checar eso seria el siguiente espero qt sirva


void Llenar(){
    try{
        Conn=Mysql.getConnection();
        String [] titulos ={"Id","Nombre","Direccion", "Telefono", "Correo"};
        String sql="select * from contactos";
        model=new DefaultTableModel(null, titulos);
        sent=Conn.createStatement();
        ResultSet rs=sent.executeQuery(sql);

        String fila []= new String [5];

        while(rs.next()){
            fila
  • =rs.getString("id");
           fila [1]=rs.getString("nombre");
            fila [2]=rs.getString("direccion");
            fila [3]=rs.getString("telefono");
            fila [4]=rs.getString("correo");

            model.addRow(fila);

        }
jTable1.setModel(model);
      
    }catch(Exception e){
e.printStackTrace();
    }
}
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines