Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - DIANA KARINA HM

#1
Java / Re: obtener datos de una lista?
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
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
Java / Re: Insertar registros en BD
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
Un ejemplo de eso es
Código (java) [Seleccionar]
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public Connection getConexion()
{
  return conexion;
}

public boolean crearConexion()
{
  try {
     Class.forName("com.mysql.jdbc.Driver");
     conexion = DriverManager.getConnection("jdbc:mysql://host:puerto/baseDatos","usuario","contraseña");
  } catch (SQLException ex) {
     ex.printStackTrace();
     return false;
  } catch (ClassNotFoundException ex) {
     ex.printStackTrace();
     return false;
  }

  return true;
}

public boolean ejecutarSQL(String sql)
{
  try {
     Statement sentencia = conexion.createStatement();
     sentencia.executeUpdate(sql);
  } catch (SQLException ex) {
     ex.printStackTrace();
  return false;
  }

  return true;
}

public ResultSet ejecutarSQLSelect(String sql)
{
  ResultSet resultado;
  try {
     Statement sentencia = conexion.createStatement();
     resultado = sentencia.executeQuery(sql);
  } catch (SQLException ex) {
     ex.printStackTrace();
     return
null;
  }

  return resultado;
}


Mod: Los códigos deben ir en etiquetas GeSHi
#5
Java / Re: Habilitar textfield con radiobutton
5 Agosto 2016, 06:34 AM
Pues no se si te ayude pero podrías intentarlo así
Código (java) [Seleccionar]

public class Program {
   //GUI code
   JRadioButton b = new JRadioButton("Show");
   b.addActionListener(new ShowListener);
   public class ShowListener implements ActionListener {
       public void actionPerformed(ActionEvent e) {
           field.setEnabled(true);
       }
   }
}




Mod: Los códigos deben ir en etiquetas GeSHi
#6
Java / Re: como modificar Jtable
5 Agosto 2016, 06:28 AM
Hola pues un ejemplo que tengo que te podría ayudar seria
Código (java) [Seleccionar]
int n=ps.executeUpdate();
if(n>0)
JOptionPane.showMessageDialog(null, "datos guardados");
}catch(Exception e){
   JOptionPane.showMessageDialog(null, "error"+ e.getMessage());
}
Llenar();
Limpiar();
   }                                          

   private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {                                        
Limpiar();
Habilitar();
       // TODO add your handling code here:
   }
 private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {                                    
if(evt.getButton()==1){
  try{
      Habilitar();
       int fila=jTable1.getSelectedRow();
       String sql="select * from contactos where id="+jTable1.getValueAt(fila,0);
       sent=Conn.createStatement();
       ResultSet rs=sent.executeQuery(sql);
       rs.next();
       txtNombre.setText(rs.getString("nombre"));
       txtDireccion.setText(rs.getString("direccion"));
       txtTelefono.setText(rs.getString("telefono"));
       txtCorreo.setText(rs.getString("correo"));

}catch(Exception e){
   e.printStackTrace();
}
   }
   }    
   


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

Código (java) [Seleccionar]
/**
*
* @author DIANA
*/
public class Palindromo {

   public static boolean esPalindromo(String palabra) {
       return esPalindromo(palabra, 0, palabra.length() - 1);
   }

   private static boolean esPalindromo(String palabra, int ini, int fin) {
       if (fin - ini + 1 == 0 || fin - ini + 1 == 1) {
           return true;
       } else {
           if (palabra.charAt(ini) == palabra.charAt(fin)) {
               return esPalindromo(palabra, ini + 1, fin - 1);
           } else {
               return false;
           }
       }
   }
}



#8
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();
       }
    }