Mostrando entradas con la etiqueta java. Mostrar todas las entradas
Mostrando entradas con la etiqueta java. Mostrar todas las entradas

30 jul 2019

Un proyecto en Java swing OLVIDADO ... primera parte.

Fue un prototipo que hice para una empresa de trailers, sus sistema lo hacian a mano y lo que se pretendia era ayudar en la nomina, registro, y algunas otras cuestiones para minimizar el tiempo. AL final no se logro mucho ya que nunca se me pago pero el prototipo se quedo. Aqui muestro unos videos, de las pantallas ya que se iba crear un sistema en red.


Al trabajar como freelance me acople a los horarios de la empresa, ya que tenia que estar ahi para checar el proceso de como se trabaja dentro de la empresa, habia momentos que los libros de java me generaban mas dudas que respuestas, ya que java aunque no habia vuelto a trabajar con el decidi retomarlo ya que era mas flexible, a mi parecer. 
Java era o sigue siendo un lenguaje de programacion muy usado. Pero el sistema necesitaba algo visual. 
Le habia comentado que usaramos PHP otro lenguaje de programacion web pero no se convencio ya que la persona encargada queria algo visual y con botones.

Login.java
package inicio;
import ConexionBaseDatos.BdConexion;
import ConexionBaseDatos.conectar;

import javax.swing.JOptionPane;

import java.sql.*;
import Menus.MenuDeOpciones;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

    

/**
 *
 * @author jektour
 */
public class Login1 extends javax.swing.JFrame {
    //String [] Usuario = ["Hmgn", "Miguel", "Hector", "Sergio"];
    
    static String cap;
    static String usuarioX;
    
    conectar cc= new conectar();
    Connection cn= cc.conexion();

    public static String getCap() {
        return cap;
    }

    public static String getUsuarioX() {
        return usuarioX;
    }

    public JPasswordField getTxtPassword() {
        return txtPassword;
    }

    public JTextField getTxtUsuario() {
        return txtUsuario;
    }

    public static void setCap(String cap) {
        Login1.cap = cap;
    }

    public static void setUsuarioX(String usuarioX) {
        Login1.usuarioX = usuarioX;
    }

    public void setTxtPassword(JPasswordField txtPassword) {
        this.txtPassword = txtPassword;
    }

    public void setTxtUsuario(JTextField txtUsuario) {
        this.txtUsuario = txtUsuario;
    }
    

    
      
    /**
     * Creates new form Login1
     */
    public Login1() {
       
         
        initComponents();
        
        
        
    }
    
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel25 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtUsuario = new javax.swing.JTextField();
        btnAceptar = new javax.swing.JButton();
        txtPassword = new javax.swing.JPasswordField();
        btnSalir = new javax.swing.JButton();

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setUndecorated(true);

        jPanel1.setPreferredSize(new java.awt.Dimension(652, 308));

        jLabel25.setFont(new java.awt.Font("Lucida Grande", 1, 24)); // NOI18N
        jLabel25.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel25.setText("AutoLineas MRD S.A. DE CV");

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 1, 24)); // NOI18N
        jLabel1.setText("Bienvenido");

        jLabel2.setText("Usuario:");

        jLabel3.setText("Password:");

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        txtPassword.setToolTipText("");
        txtPassword.setVerifyInputWhenFocusTarget(false);

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

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(34, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel25, javax.swing.GroupLayout.PREFERRED_SIZE, 511, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(76, 76, 76))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(55, 55, 55)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(150, 150, 150))))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(268, 268, 268)
                        .addComponent(jLabel1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(214, 214, 214)
                        .addComponent(btnAceptar)
                        .addGap(65, 65, 65)
                        .addComponent(btnSalir)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel25)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addGap(23, 23, 23)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAceptar)
                    .addComponent(btnSalir))
                .addGap(44, 44, 44))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
        );

        pack();
    }//
//GEN-END:initComponents

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
      
      
      String usuario = txtUsuario.getText();
       
       String password = new String(txtPassword.getPassword());
      
       if(("".equals(usuario)) && ("".equals(password))){
            JOptionPane.showMessageDialog(null,"No hay datos de entrada en login");
        }else{
           acceder(usuario, password);
           
       
       }
       

    }//GEN-LAST:event_btnAceptarActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        System.exit(0);
    }//GEN-LAST:event_btnSalirActionPerformed

  public void acceder(String usuario, String password){
        String user = usuario;
        String pass = password;
        String clave = "";
        
        //String cap="";
        String nick = "";
        String sql="SELECT * FROM usuario WHERE usuario='"+user+"' && password='"+pass+"'";
        try{
            
            Statement st = cn.createStatement();
            ResultSet rs = st.executeQuery(sql);
            while(rs.next()){
                cap= rs.getString("tipousuario");
                
                nick = rs.getString("usuario");
                usuarioX = rs.getString("NombreUsuario");
                clave = rs.getString("password");
            }
            if (user.equals(nick) && (pass.equals(clave))){
               JOptionPane.showMessageDialog(null,"Bienvenido: " + usuarioX);
               this.dispose();
               MenuDeOpciones menu = new MenuDeOpciones();
                menu.setLocationRelativeTo(null);
                menu.setVisible(true); 
            }else{
                JOptionPane.showMessageDialog(null, "Usuario o contraseña incorrecta");
                txtUsuario.setText("");
                txtPassword.setText("");
            }
           
            
            
        
        }catch (Exception e) {
        
        
    }
  }  
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void Login(String args[]) {
        /* Set the Nimbus look and feel */
        //
        /* 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(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Login1().setVisible(true);
                
                
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables
}





2 ago 2008

Programas Java

Me hicieron hacer esto pequeños programas en Java, realemnte hace mucho que no lo hacia ya que me dedique a programar en javascript pero valio la pena jeje

Selección: Este método consiste en buscar el elemento más pequeño del array y ponerlo en primera posición; luego, entre los restantes, se busca el elemento más pequeño y se coloca en segudo lugar, y así sucesivamente hasta colocar el último elemento. Por ejemplo, si tenemos el array {40,21,4,9,10,35}, los pasos a seguir son:

{4,21,40,9,10,35} <-- Se coloca el 4, el más pequeño, en primera posición : se cambia el 4 por el 40.
{4,9,40,21,10,35} <-- Se coloca el 9, en segunda posición: se cambia el 9 por el 21.
{4,9,10,21,40,35} <-- Se coloca el 10, en tercera posición: se cambia el 10 por el 40.
{4,9,10,21,40,35} <-- Se coloca el 21, en tercera posición: ya está colocado.
{4,9,10,21,35,40} <-- Se coloca el 35, en tercera posición: se cambia el 35 por el 40.

class Algoritmo1 {
public static void main(String[] args){
int caja[]=new int[6];
caja[0]=14;
caja[1]=21;
caja[2]=40;
caja[3]=9;
caja[4]=35;
caja[5]=10;
System.out.println("Se muestra el arreglo en desorden");
for(int i=0;i<caja.length;i++){
System.out.print(caja[i]);
}
System.out.println("Se muestra ahora el arreglo ordenado");
int x;
int y;
int tempo, min;
int cap=caja.length;
y=0;
while (y<cap-1){
min=y;
for(x=y+1;x<cap; x++){
if (caja[x]<caja[min]){
min=y;
tempo=caja[x];
caja[x]=caja[min];
caja[min]=tempo;
}
}
y++;
}
for(int i=0;i<caja.length;i++)
System.out.println(caja[i]);

}
}

Array contenido en uno mas grande. Dados dos arrays de números enteros A y B de longitud n y m respectivamente, siendo n >= m, determinar si B está contenido en A. Ejemplo:
A = {2,3,4,5,6,7,-3}
B = {7,-3} -> contenido; B = {5,7} -> no contenido; B = {3,2} -> no contenido

public class algoritmo7 {
public static void main(String[] args){
int A[] = {2,3,4,5,6,7,-3};
int B[]={6,7,-3};
int m=0;
boolean sigue=false;
for(int i=0; i<A.length;i++){
for (int j=0; j<B.length;j++){
if(B[j]==A[i]){
//C[j]=A[i];
m++;
sigue=true;
}else{
sigue=false;
}
}
}
if ((m==B.length) && (sigue==true)){
System.out.println("Contenido");
}else
System.out.println("NO Contenido");
}

}

Potencia. Dados dos números a (número entero) y b (número natural mayor o igual que cero) determinar a^b.

public class algoritmo4 {
static int potencias(int a, int b){
if(b==0){
return 1;
} else
return a * potencias(a,b-1);
}

public static void main(String[] args){
System.out.println(potencias(3,6));
}
}

23 jun 2008

Galeria de imagenes en Java

netbeans2 Mi IDE o complador de programacion en Java

Lo que haremos es una mini galeria sencilla de imagenes in usar una base de datos, ya que es bien sabido que una base de datos es como un conjunto de vectores asi que usaremos vectores como ven....

Abrimos Netbeans y diseñamos con el editor un pequeño frame y un panel dentro de estos insertamos cada uno de los objetos.

Jlabel, 2 JButton y quedara mas o menos a si..

galeria1

En la fuente del codigo quedara algo asi, Netbeans lo que hace es simplificar el diseño,

 

public class Galeria1_1 extends javax.swing.JFrame {
    /** Creates new form Galeria1_1 */
    public Galeria1_1() {
        initComponents();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jButton1.setText("Atras");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Tahoma", 1, 14));
        jButton2.setText("Adelante");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 346, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .add(71, 71, 71)
                .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 86, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 66, Short.MAX_VALUE)
                .add(jButton2)
                .add(50, 50, 50))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 447, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 45, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        pack();
    }// </editor-fold>

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        fotoAdelante();
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        fotoAtras();
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Galeria1_1().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration
}

Como ven en la parte de JButton tenemos dos procedimientos que es fotoadelante y fotoatras aqui se va encargar este metodo de moverse dentro de la galeria o mas bien de los vectores.

 

Agregamos elementos..importamos paquetes

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

y demas elementos

public class Galeria extends javax.swing.JFrame {
    Image foto;
    Vector imagenes = new Vector();
    int index = 0;
    String folder ="";

Cargamos el album de imagenes de la carpeta donde se encuentran...

void cargarAlbum(){
          imagenes.clear();
          index = 0;
          String album = ("C:\\herramienta\\hddr\\photos");
          File albumCarpeta = new File (album); 
          folder = albumCarpeta.getName();
          System.out.println(albumCarpeta.getName());
          File[] fotos = albumCarpeta.listFiles();
          for (int i=0; i<fotos.length; i++)
              if (fotos[i].isFile()){
                  imagenes.add(fotos[i].getName());         
                  System.out.println(fotos[i].getName());
              }
                          jLabel1.setIcon(new javax.swing.ImageIcon(folder+"\\"+(String)imagenes.elementAt(0)));
  }

 

Despues agregamos lo dos procedimiento del movimiento..

void fotoAdelante(){
      System.out.println("Adelante ..");
      if ((index+1) < imagenes.size()){
          index++;
        ImageIcon imagen = new ImageIcon(folder+"\\"+(String)imagenes.elementAt(index));
        jLabel1.setIcon(imagen);
        System.out.println(index + " : " + folder+"\\"+(String)imagenes.elementAt(index));
    }
    else
    {
        JOptionPane.showMessageDialog(null, "Fin de las Fotos del Album","Atencion",JOptionPane.OK_OPTION );     
    }
  } 
  void fotoAtras(){
      System.out.println("Atras ..");
      if ((index-1) > -1){
          index--;
        ImageIcon imagen = new ImageIcon(folder+"\\"+(String)imagenes.elementAt(index));
        jLabel1.setIcon(imagen);
        System.out.println(index + " : " + folder+"\\"+(String)imagenes.elementAt(index));
    }
    else
    {
        JOptionPane.showMessageDialog(null, "Fin de las Fotos del Album","Atencion",JOptionPane.OK_OPTION );     
    }
  }

Y LISTO, tenemos nuestra galeria de imagenes usando Vectores jejeje que les parece....

 

Related Posts Plugin for WordPress, Blogger...