Este es el Main que le hice a la aplicacion anterior.
El programa guarda los datos por medio de una archivo *.csv
==================================================
/*
* Main.java
*
* Created on 31 de mayo de 2008, 04:55 AM
*/
/**
*
* @author Rey Salcedo
*/
import javax.swing.*;
public class Main extends javax.swing.JFrame {
/** Creates new form Main */
public Main() {
initComponents();
}
private void Limpiar(){
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
}
private void Restaurar(){
jLabel1.setText("Nombre");
jLabel2.setText("Modelo");
jLabel3.setText("Rendimiento x galon");
jLabel4.setText("Precio");
jLabel5.setText("Cantidad");
jTextField1.setEnabled(true);
jTextField2.setEnabled(true);
jTextField3.setEnabled(true);
jTextField4.setEnabled(true);
jTextField5.setEnabled(true);
jButton1.setEnabled(true);
jButton2.setEnabled(true);
jButton3.setEnabled(true);
jButton4.setEnabled(true);
jButton5.setEnabled(true);
jButton6.setEnabled(true);
jButton7.setEnabled(true);
jButton8.setEnabled(true);
}
/** 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() {
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jButton8 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("ContaVehiculo-Free IDE 1.0");
addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseExited(java.awt.event.MouseEvent evt) {
formMouseExited(evt);
}
});
jPanel1.setBackground(new java.awt.Color(24, 240, 240));
jPanel1.setBorder(new javax.swing.border.MatteBorder(null));
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jTextField1FocusGained(evt);
}
});
jTextField3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField3ActionPerformed(evt);
}
});
jTextField4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField4ActionPerformed(evt);
}
});
jTextField5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField5ActionPerformed(evt);
}
});
jLabel1.setText("Nombre");
jLabel2.setText("Modelo");
jLabel3.setText("Rendimiento x galon");
jLabel4.setText("Precio");
jLabel5.setText("Cantidad");
jLabel6.setFont(new java.awt.Font("Arial", 0, 24));
jLabel6.setText("Datos automovil");
jButton8.setText("Limpiar");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jLabel4)
.add(jLabel5)
.add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 56, Short.MAX_VALUE)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jTextField5)
.add(jTextField4)
.add(jTextField3)
.add(jTextField2)
.add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)))
.add(jPanel1Layout.createSequentialGroup()
.add(80, 80, 80)
.add(jLabel6))
.add(org.jdesktop.layout.GroupLayout.TRAILING, jButton8))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jLabel6)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 19, Short.MAX_VALUE)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1))
.add(18, 18, 18)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel2))
.add(14, 14, 14)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel3)
.add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(17, 17, 17)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel4)
.add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(18, 18, 18)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel5)
.add(jTextField5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(18, 18, 18)
.add(jButton8)
.add(4, 4, 4))
);
jPanel2.setBackground(new java.awt.Color(40, 240, 240));
jPanel2.setBorder(new javax.swing.border.MatteBorder(null));
jButton1.setText("Agregar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Actualizar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Eliminar");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("Buscar");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setText("Venta");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setText("Mostrar");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jButton7.setText("Salir");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
jLabel7.setFont(new java.awt.Font("Arial", 0, 13));
jLabel7.setText("Operaciones");
org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel7)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jButton7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jButton6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jButton5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jButton4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jButton3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
.add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.add(jLabel7)
.add(24, 24, 24)
.add(jButton1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton4)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton5)
.add(4, 4, 4)
.add(jButton6)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton7)
.addContainerGap(21, Short.MAX_VALUE))
);
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(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(11, 11, 11)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Procedimientos pro = new Procedimientos();
String a,b,c,d,e;
boolean agregar;
a=pro.minusculas(jTextField1.getText());
b=pro.minusculas(jTextField2.getText());
c=pro.minusculas(jTextField3.getText());
d=pro.minusculas(jTextField4.getText());
e=pro.minusculas(jTextField5.getText());
boolean v=pro.buscarProducto(a);
if(!a.equals("")){
if (v){
boolean valor =pro.MensajeModelo(b, c, d, e);
if (valor){
boolean v2=pro.CaracterEspecial(a);
if (v2){
pro.IngresarVehiculo(a+";"+b+";"+c+";"+d+";"+e);
JOptionPane.showMessageDialog(null,"Los datos del vehiculo "+a+" han sido agregados","Mensaje",2);
Limpiar();
}else{
JOptionPane.showMessageDialog(null,"No es permitido usar el caracter (
, intente nuevamente","Mensaje",2);
}
}
}else{
JOptionPane.showMessageDialog(null,"Este vehiculo ya existe, intente actualizando","Mensaje",2);
jTextField1.setText(a);
jTextField2.setText(pro.SetB());
jTextField3.setText(pro.SetC());
jTextField4.setText(pro.SetD());
jTextField5.setText(pro.SetE());
}
}else{
JOptionPane.showMessageDialog(null,"Digite el nombre del vehiculo","Mensaje",2);
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Procedimientos pro = new Procedimientos();
String g="";
g =pro.minusculas(JOptionPane.showInputDialog("Digite el vehiculo a buscar"));
boolean valor=pro.buscarProducto(g);
if (!valor){
jTextField1.setText(pro.SetA());
jTextField2.setText(pro.SetB());
jTextField3.setText(pro.SetC());
jTextField4.setText(pro.SetD());
jTextField5.setText(pro.SetE());
JOptionPane.showMessageDialog(null,"Busqueda finalizada, desde el resultado puedes eliminar y/o actualizar","Mensaje",2);
}else{
JOptionPane.showMessageDialog(null,"El vehiculo buscado no esta en inventario","Mensaje",2);
}
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.hide();
Mostrar op = new Mostrar();
op.show();
}
private void jTextField1FocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Limpiar();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Procedimientos pro = new Procedimientos();
String a,b,c,d,e;
a=pro.minusculas(jTextField1.getText());
b=pro.minusculas(jTextField2.getText());
c=pro.minusculas(jTextField3.getText());
d=pro.minusculas(jTextField4.getText());
e=pro.minusculas(jTextField5.getText());
boolean v=pro.buscarProducto(a);
if (!v){
boolean valor =pro.MensajeModelo(b, c, d, e);
if(valor){
pro.actualizarProducto(a, b, c, d, e);
JOptionPane.showMessageDialog(null,"El vehiculo "+a+" ha sido actualizado","Mensaje",2);
}
}else{
JOptionPane.showMessageDialog(null,"El vehiculo "+a+" no se puede actualizar, no existe en inventario; ¡rectifique!","Mensaje",2);
}
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int opcion = JOptionPane.showConfirmDialog(this,"En realidad desea salir de la aplicación. ¿Continuar?", "Salir",JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (opcion == JOptionPane.YES_OPTION) {
this.dispose();//te cierra la ventana
}else{
//¿¿¿AQUI QUE IRIA PARA QUE NO TE LA CIERRE???
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Procedimientos pro = new Procedimientos();
String a;
a = pro.minusculas(jTextField1.getText());
String g =pro.minusculas(JOptionPane.showInputDialog("Digite el vehiculo a eliminar"));
if (!pro.buscarProducto(g)){
if (pro.CaracterEspecial(g)){
int opcion = JOptionPane.showConfirmDialog(this,"El registro será eliminado de manera definitiva. ¿desea continuar?", "Salir",JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (opcion == JOptionPane.YES_OPTION) {
pro.eliminarProducto(g);
JOptionPane.showMessageDialog(null,"El vehiculo "+g+" ha sido eliminado","Mensaje",2);
}else{
//¿¿¿AQUI QUE IRIA PARA QUE NO TE LA CIERRE???
}
}else{
JOptionPane.showMessageDialog(null,"No se aceptar el caracter (
, !VERIFICA¡","Mensaje",2);
}
}else{
JOptionPane.showMessageDialog(null,"El vehiculo "+a+" no esta en inventario","Mensaje",2);
}
Limpiar();
}
boolean interruptor=true;
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.hide();
Vender op =new Vender();
op.show();
}
private void formMouseExited(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Main().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.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
// End of variables declaration
}