import java.awt.BorderLayout; import java.awt.EventQueue;
import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JTabbedPane; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JButton; import javax.swing.JTextField; import javax.swing.JTable; import javax.swing.table.DefaultTableModel;
import Variables.Factura;
import javax.swing.JScrollPane; import javax.swing.border.TitledBorder; import java.awt.Font; import java.awt.Color; import java.awt.SystemColor; import javax.swing.JComboBox; import javax.swing.DefaultComboBoxModel; import java.awt.event.ActionListener; import java.awt.print.PrinterException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.text.MessageFormat; import java.awt.event.ActionEvent;
public class YAI extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTextField tnumero;
private JTextField tfecha;
private JTextField tcodigo;
private JTextField tnombre;
private JTextField tmarca;
private JTextField tcantidad;
private JTextField tprecio;
private JTable tablefactura;
private JTable tableVehiculo;
private JTextField tano;
private JTable table;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
YAI frame = new YAI();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public YAI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 757, 522);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setBounds(0, 0, 741, 483);
contentPane.add(tabbedPane);
JPanel Productos = new JPanel();
Productos.setToolTipText("");
tabbedPane.addTab("Productos", null, Productos, null);
Productos.setLayout(null);
JLabel tablev = new JLabel("Productos");
tablev.setBounds(10, 11, 70, 22);
Productos.add(tablev);
textField = new JTextField();
textField.setBounds(79, 12, 427, 20);
Productos.add(textField);
textField.setColumns(10);
JButton btnBuscar = new JButton("Buscar");
btnBuscar.setBounds(637, 11, 89, 23);
Productos.add(btnBuscar);
JButton btnAgregar = new JButton("Agregar");
btnAgregar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
AggVehiculo agregarv = new AggVehiculo();
agregarv.setVisible(true);
}
});
btnAgregar.setBounds(637, 44, 89, 23);
Productos.add(btnAgregar);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 48, 610, 359);
Productos.add(scrollPane);
table = new JTable();
scrollPane.setViewportView(table);
table.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"C\u00F3digo", "Nombre", "Marca", "Color", "Combustible", "A\u00F1o", "Precio"
}
));
table.setEditingRow(0);
table.setEditingColumn(0);
JPanel Clientes = new JPanel();
tabbedPane.addTab("Clientes", null, Clientes, null);
Clientes.setLayout(null);
JButton btnAgregarCliente = new JButton("Agregar Cliente");
btnAgregarCliente.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
AgreCliente ac = new AgreCliente();
ac.setVisible(true);
}
});
btnAgregarCliente.setBounds(10, 369, 143, 23);
Clientes.add(btnAgregarCliente);
JPanel Vendedores = new JPanel();
Vendedores.setBorder(new TitledBorder(null, "Facturaci\u00F3n", TitledBorder.RIGHT, TitledBorder.TOP, null, null));
tabbedPane.addTab("Factura", null, Vendedores, null);
Vendedores.setLayout(null);
JLabel lblNoFactura = new JLabel("No. Factura");
lblNoFactura.setBounds(10, 11, 65, 20);
Vendedores.add(lblNoFactura);
tnumero = new JTextField();
tnumero.setBounds(75, 11, 86, 20);
Vendedores.add(tnumero);
tnumero.setColumns(10);
JLabel lblFecha = new JLabel("Fecha");
lblFecha.setBounds(71, 54, 46, 14);
Vendedores.add(lblFecha);
tfecha = new JTextField();
tfecha.setBounds(105, 51, 86, 20);
Vendedores.add(tfecha);
tfecha.setColumns(10);
JLabel lblCodigo = new JLabel("Codigo");
lblCodigo.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblCodigo.setBounds(10, 108, 65, 20);
Vendedores.add(lblCodigo);
JLabel lblModelo = new JLabel("Nombre");
lblModelo.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblModelo.setBounds(71, 108, 76, 20);
Vendedores.add(lblModelo);
JLabel lblMarca = new JLabel("Marca");
lblMarca.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblMarca.setBounds(228, 108, 46, 20);
Vendedores.add(lblMarca);
JLabel lblCantidad_1 = new JLabel("Cantidad");
lblCantidad_1.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblCantidad_1.setBounds(373, 108, 65, 20);
Vendedores.add(lblCantidad_1);
JLabel lblPrecio = new JLabel("Precio");
lblPrecio.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblPrecio.setBounds(481, 108, 54, 20);
Vendedores.add(lblPrecio);
JLabel lblTotal = new JLabel("Total");
lblTotal.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblTotal.setBounds(585, 108, 46, 20);
Vendedores.add(lblTotal);
tcodigo = new JTextField();
tcodigo.setBounds(10, 134, 54, 20);
Vendedores.add(tcodigo);
tcodigo.setColumns(10);
tnombre = new JTextField();
tnombre.setBounds(71, 134, 120, 20);
Vendedores.add(tnombre);
tnombre.setColumns(10);
tano = new JTextField();
tano.setBounds(290, 134, 73, 20);
Vendedores.add(tano);
tano.setColumns(10);
tmarca = new JTextField();
tmarca.setBounds(201, 134, 86, 20);
Vendedores.add(tmarca);
tmarca.setColumns(10);
tcantidad = new JTextField();
tcantidad.setBounds(373, 134, 105, 20);
Vendedores.add(tcantidad);
tcantidad.setColumns(10);
tprecio = new JTextField();
tprecio.setBounds(481, 134, 97, 20);
Vendedores.add(tprecio);
tprecio.setColumns(10);
JPanel panel_2 = new JPanel();
panel_2.setBounds(10, 165, 645, 236);
Vendedores.add(panel_2);
panel_2.setLayout(null);
JScrollPane scrollPane_2 = new JScrollPane();
scrollPane_2.setBounds(0, 0, 645, 236);
panel_2.add(scrollPane_2);
tablefactura = new JTable();
scrollPane_2.setViewportView(tablefactura);
tablefactura.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"C\u00F3digo", "Nombre", "Marca", "Año", "Cantidad", "Precio", "Total"
}
));
JLabel lblYarlinAutosImport = new JLabel("Yarlin Autos Import S.A");
lblYarlinAutosImport.setForeground(new Color(0, 0, 205));
lblYarlinAutosImport.setFont(new Font("Britannic Bold", Font.PLAIN, 20));
lblYarlinAutosImport.setBounds(242, 11, 227, 30);
Vendedores.add(lblYarlinAutosImport);
JLabel lblNewLabel_1 = new JLabel("Carretera Mella/K #5 \r\n");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 13));
lblNewLabel_1.setBounds(284, 33, 131, 25);
Vendedores.add(lblNewLabel_1);
JLabel lblTell = new JLabel("Tell: 829-981-9169 ");
lblTell.setBounds(294, 54, 105, 14);
Vendedores.add(lblTell);
JButton btnNewButton = new JButton("+");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Factura f = new Factura(tcodigo.getText(),
tnombre.getText(),
tmarca.getText(),
tano.getText(),
Integer.parseInt(tnumero.getText()),
tfecha.getText(),
Double.parseDouble(tprecio.getText()),
Integer.parseInt(tcantidad.getText())
);
DefaultTableModel modelo = (DefaultTableModel) tablefactura.getModel();
Object [] fila = new Object [7];
fila[0] = f.getCodigo();
fila[1] = f.getNombre();
fila[2] = f.getMarca();
fila[3] = f.getAño();
fila[4] = f.getCantidad();
fila[5] = f.getPrecio();
fila[6] = String.valueOf(f.getPrecio()*f.getCantidad());
modelo.addRow(fila);
}
});
btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnNewButton.setBounds(10, 410, 89, 34);
Vendedores.add(btnNewButton);
JLabel label = new JLabel("0.00");
label.setFont(new Font("Tahoma", Font.PLAIN, 15));
label.setBounds(595, 135, 46, 14);
Vendedores.add(label);
JComboBox comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] {"Abono", "Finalizado"}));
comboBox.setBounds(558, 50, 97, 22);
Vendedores.add(comboBox);
JLabel lblPago = new JLabel("Pago:");
lblPago.setBounds(520, 54, 37, 14);
Vendedores.add(lblPago);
JLabel lblAo = new JLabel("A\u00F1o");
lblAo.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblAo.setBounds(294, 108, 54, 20);
Vendedores.add(lblAo);
//AQUI EL BOTON DE PRINT *************************************
JButton btnPrint = new JButton("Print");
btnPrint.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnPrint.setBounds(115, 419, 89, 23);
Vendedores.add(btnPrint);
JPanel panel = new JPanel();
tabbedPane.addTab("Vendedores", null, panel, null);
//MOSTRAR VEHICULOS EN LAS TABLAS
Conect conexion = new Conect();
Connection conect = conexion.conectar();
String mysql = "SELECT * FROM vehículos";
DefaultTableModel model = new DefaultTableModel();
model.addColumn("Código");
model.addColumn("Modelo");
model.addColumn("Marca");
model.addColumn("Color");
model.addColumn("Combustible");
model.addColumn("Año");
model.addColumn("Precio");
table.setModel(model);
String[] dato = new String [7];
try {
Statement st = conect.createStatement();
ResultSet result = st.executeQuery(mysql);
while (result.next()) {
dato[0]=result.getString(1);
dato[1]=result.getString(2);
dato[2]=result.getString(3);
dato[3]=result.getString(4);
dato[4]=result.getString(5);
dato[5]=result.getString(6);
dato[6]=result.getString(7);
model.addRow(dato);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}