List of usage examples for javax.swing JDialog setTitle
public void setTitle(String title)
From source file:userinterface.properties.GUIGraphHandler.java
public void plotNewFunction() { JDialog dialog; JRadioButton radio2d, radio3d, newGraph, existingGraph; JTextField functionField, seriesName; JButton ok, cancel;//from w w w . j a va 2 s. com JComboBox<String> chartOptions; JLabel example; //init all the fields of the dialog dialog = new JDialog(GUIPrism.getGUI()); radio2d = new JRadioButton("2D"); radio3d = new JRadioButton("3D"); newGraph = new JRadioButton("New Graph"); existingGraph = new JRadioButton("Exisiting"); chartOptions = new JComboBox<String>(); functionField = new JTextField(); ok = new JButton("Plot"); cancel = new JButton("Cancel"); seriesName = new JTextField(); example = new JLabel("<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>"); example.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { example.setCursor(new Cursor(Cursor.HAND_CURSOR)); example.setForeground(Color.BLUE); } @Override public void mouseExited(MouseEvent e) { example.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); example.setForeground(Color.BLACK); } @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (radio2d.isSelected()) { functionField.setText("x/2 + 5"); } else { functionField.setText("x+y+5"); } functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15)); functionField.setForeground(Color.BLACK); } } }); //set dialog properties dialog.setSize(400, 350); dialog.setTitle("Plot a new function"); dialog.setModal(true); dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS)); dialog.setLocationRelativeTo(GUIPrism.getGUI()); //add every component to their dedicated panels JPanel graphTypePanel = new JPanel(new FlowLayout()); graphTypePanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function type")); graphTypePanel.add(radio2d); graphTypePanel.add(radio3d); JPanel functionFieldPanel = new JPanel(new BorderLayout()); functionFieldPanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function")); functionFieldPanel.add(functionField, BorderLayout.CENTER); functionFieldPanel.add(example, BorderLayout.SOUTH); JPanel chartSelectPanel = new JPanel(); chartSelectPanel.setLayout(new BoxLayout(chartSelectPanel, BoxLayout.Y_AXIS)); chartSelectPanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Plot function to")); JPanel radioPlotPanel = new JPanel(new FlowLayout()); radioPlotPanel.add(newGraph); radioPlotPanel.add(existingGraph); JPanel chartOptionsPanel = new JPanel(new FlowLayout()); chartOptionsPanel.add(chartOptions); chartSelectPanel.add(radioPlotPanel); chartSelectPanel.add(chartOptionsPanel); JPanel bottomControlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomControlPanel.add(ok); bottomControlPanel.add(cancel); JPanel seriesNamePanel = new JPanel(new BorderLayout()); seriesNamePanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name")); seriesNamePanel.add(seriesName, BorderLayout.CENTER); // add all the panels to the dialog dialog.add(graphTypePanel); dialog.add(functionFieldPanel); dialog.add(chartSelectPanel); dialog.add(seriesNamePanel); dialog.add(bottomControlPanel); // do all the enables and set properties radio2d.setSelected(true); newGraph.setSelected(true); chartOptions.setEnabled(false); functionField.setText("Add function expression here...."); functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15)); functionField.setForeground(Color.GRAY); seriesName.setText("New function"); ok.setMnemonic('P'); cancel.setMnemonic('C'); example.setToolTipText("click to try out"); ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ok.doClick(); } }); cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); cancel.getActionMap().put("cancel", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); boolean found = false; for (int i = 0; i < theTabs.getTabCount(); i++) { if (theTabs.getComponentAt(i) instanceof Graph) { chartOptions.addItem(getGraphName(i)); found = true; } } if (!found) { existingGraph.setEnabled(false); chartOptions.setEnabled(false); } //add all the action listeners radio2d.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (radio2d.isSelected()) { radio3d.setSelected(false); if (chartOptions.getItemCount() > 0) { existingGraph.setEnabled(true); chartOptions.setEnabled(true); } example.setText( "<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>"); } } }); radio3d.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (radio3d.isSelected()) { radio2d.setSelected(false); newGraph.setSelected(true); existingGraph.setEnabled(false); chartOptions.setEnabled(false); example.setText("<html><font size=3 color=red>Example:</font><font size=3>x+y+5</font></html>"); } } }); newGraph.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (newGraph.isSelected()) { existingGraph.setSelected(false); chartOptions.setEnabled(false); } } }); existingGraph.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (existingGraph.isSelected()) { newGraph.setSelected(false); chartOptions.setEnabled(true); } } }); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String function = functionField.getText(); Expression expr = null; try { expr = GUIPrism.getGUI().getPrism().parseSingleExpressionString(function); expr = (Expression) expr.accept(new ASTTraverseModify() { @Override public Object visit(ExpressionIdent e) throws PrismLangException { return new ExpressionConstant(e.getName(), TypeDouble.getInstance()); } }); expr.typeCheck(); expr.semanticCheck(); } catch (PrismLangException e1) { // for copying style JLabel label = new JLabel(); // html content in our case the error we want to show JEditorPane ep = new JEditorPane("text/html", "<html> There was an error parsing the function. To read about what built-in" + " functions are supported <br>and some more information on the functions, visit " + "<a href='http://www.prismmodelchecker.org/manual/ThePRISMLanguage/Expressions'>Prism expressions site</a>." + "<br><br><font color=red>Error: </font>" + e1.getMessage() + " </html>"); // handle link events ep.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { try { Desktop.getDesktop().browse(e.getURL().toURI()); } catch (IOException | URISyntaxException e1) { e1.printStackTrace(); } } } }); ep.setEditable(false); ep.setBackground(label.getBackground()); // show the error dialog JOptionPane.showMessageDialog(dialog, ep, "Parse Error", JOptionPane.ERROR_MESSAGE); return; } if (radio2d.isSelected()) { ParametricGraph graph = null; if (newGraph.isSelected()) { graph = new ParametricGraph(""); } else { for (int i = 0; i < theTabs.getComponentCount(); i++) { if (theTabs.getTitleAt(i).equals(chartOptions.getSelectedItem())) { graph = (ParametricGraph) theTabs.getComponent(i); } } } dialog.dispose(); defineConstantsAndPlot(expr, graph, seriesName.getText(), newGraph.isSelected(), true); } else if (radio3d.isSelected()) { try { expr = (Expression) expr.accept(new ASTTraverseModify() { @Override public Object visit(ExpressionIdent e) throws PrismLangException { return new ExpressionConstant(e.getName(), TypeDouble.getInstance()); } }); expr.semanticCheck(); expr.typeCheck(); } catch (PrismLangException e1) { e1.printStackTrace(); } if (expr.getAllConstants().size() < 2) { JOptionPane.showMessageDialog(dialog, "There are not enough variables in the function to plot a 3D chart!", "Error", JOptionPane.ERROR_MESSAGE); return; } // its always a new graph ParametricGraph3D graph = new ParametricGraph3D(expr); dialog.dispose(); defineConstantsAndPlot(expr, graph, seriesName.getText(), true, false); } dialog.dispose(); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); // we will show info about the function when field is out of focus functionField.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { if (!functionField.getText().equals("")) { return; } functionField.setText("Add function expression here...."); functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15)); functionField.setForeground(Color.GRAY); } @Override public void focusGained(FocusEvent e) { if (!functionField.getText().equals("Add function expression here....")) { return; } functionField.setForeground(Color.BLACK); functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15)); functionField.setText(""); } }); // show the dialog dialog.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void TablaDeFacturaProductoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaDeFacturaProductoMouseClicked final int fila = TablaDeFacturaProducto.getSelectedRow(); final DefaultTableModel modeloTabla = (DefaultTableModel) TablaDeFacturaProducto.getModel(); //int identificacion = (int) TablaDeFacturaProducto.getValueAt(fila, 0); // TODO add your handling code here: final JDialog dialogoEdicionProducto = new JDialog(this); dialogoEdicionProducto.setTitle("Editar producto"); dialogoEdicionProducto.setSize(250, 150); dialogoEdicionProducto.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar producto"); c.gridx = 0;//from w ww. java2s .c o m c.gridy = 0; c.gridwidth = 3; c.insets = new Insets(15, 40, 10, 0); Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 0, 0, 0); c.gridwidth = 0; c.gridy = 1; c.gridx = 0; JLabel textoUnidades = new JLabel("Unidades"); panelDialogo.add(textoUnidades, c); c.gridy = 1; c.gridx = 1; c.gridwidth = 2; final JTextField valorUnidades = new JTextField(); valorUnidades.setText(String.valueOf(modeloTabla.getValueAt(fila, 4))); panelDialogo.add(valorUnidades, c); c.gridwidth = 1; c.gridy = 2; c.gridx = 0; JButton guardarCambios = new JButton("Guardar"); panelDialogo.add(guardarCambios, c); c.gridy = 2; c.gridx = 1; JButton eliminarProducto = new JButton("Eliminar"); panelDialogo.add(eliminarProducto, c); c.gridy = 2; c.gridx = 2; JButton botonCancelar = new JButton("Cerrar"); panelDialogo.add(botonCancelar, c); botonCancelar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEdicionProducto.dispose(); } }); eliminarProducto.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double precio = (double) modeloTabla.getValueAt(fila, 6); double precioActual = Double.parseDouble(valorActualFactura.getText()); precioActual -= precio; valorActualFactura.setText(String.valueOf(precioActual)); modeloTabla.removeRow(fila); dialogoEdicionProducto.dispose(); } }); guardarCambios.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { int numeroUnidades = Integer.parseInt(valorUnidades.getText()); modeloTabla.setValueAt(numeroUnidades, fila, 4); double precioARestar = (double) modeloTabla.getValueAt(fila, 6); double valorUnitario = Double.parseDouble((String) modeloTabla.getValueAt(fila, 5)); double precioNuevo = valorUnitario * numeroUnidades; modeloTabla.setValueAt(precioNuevo, fila, 6); double precioActual = Double.parseDouble(valorActualFactura.getText()); precioActual -= precioARestar; precioActual += precioNuevo; valorActualFactura.setText(String.valueOf(precioActual)); dialogoEdicionProducto.dispose(); } catch (Exception eve) { JOptionPane.showMessageDialog(dialogoEdicionProducto, "Por favor ingrese un valor numrico"); } } }); dialogoEdicionProducto.add(panelDialogo); dialogoEdicionProducto.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed String nombreCliente = nombreClienteReporteCliente.getText(); String identificacion = identificacionClienteCliente.getText(); try {/*from w ww.ja v a 2 s . c o m*/ //08-11-2014 listar clientes por nombre ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaClientes = new ArrayList<Cliente>(); if (nombreCliente.equals("") && identificacion.equals("")) { listaClientes = controladorCliente.obtenerClientes(); } else { int identificacionNumerico = 0; if (!identificacion.equals("")) { identificacionNumerico = Integer.parseInt(identificacion); } listaClientes = controladorCliente.obtenerClientes(nombreCliente, identificacionNumerico); } //08-11-2014 Crear dialogo de bsqueda final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(300, 300); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Buscar cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.insets = new Insets(10, 60, 10, 10); Font textoGrande = new Font("Arial", 1, 16); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); c.gridx = 0; c.gridy = 1; c.gridwidth = 2; c.insets = new Insets(10, 10, 10, 10); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); //LLenar tabla for (int i = 0; i < listaClientes.size(); i++) { Object[] data = { "1", "2" }; data[0] = listaClientes.get(i).getCliente_id(); data[1] = listaClientes.get(i).getNombre(); modeloTabla.addRow(data); } tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("Identificacin").setMinWidth(110); tablaDialogo.getColumn("Nombre").setMinWidth(110); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(220, 150)); panelDialogo.add(scroll, c); c.insets = new Insets(0, 0, 0, 10); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; JButton botonGuardarClienteDialogo = new JButton("Elegir"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = tablaDialogo.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(dialogoEditar, "Por favor seleccione una fila"); } else { Object identificacionCliente = tablaDialogo.getValueAt(row, 0); jTextFieldIdentificacionClienteReporte.setText(String.valueOf(identificacionCliente)); botonGenerarReporteCliente.setEnabled(true); dialogoEditar.dispose(); } } }); // TODO add your handling code here: } catch (Exception e) { JOptionPane.showMessageDialog(this, "El valor de la identificacin de ser numrico"); } }
From source file:interfaces.InterfazPrincipal.java
private void botonAgregarProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarProductoActionPerformed String nombre = jTextField_Factura_Producto_Nombre.getText(); String descripcion = jTextField_Factura_Producto_Descripcion.getText(); ControladorProducto controladorPro = new ControladorProducto(); String restriccion = ""; boolean encounter = true; if (!nombre.equals("")) { if (encounter) { encounter = false;/*from w w w .ja va 2 s .c o m*/ restriccion = " where "; } else { restriccion += " OR "; } restriccion += " nombre like '%" + nombre + "%'"; } if (!descripcion.equals("")) { if (encounter) { encounter = false; restriccion = " where "; } else { restriccion += " OR "; } restriccion += " descripcion like '%" + descripcion + "%'"; } ArrayList<Productos> listaDeProductos = controladorPro.getProducto(restriccion); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(600, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Buscar Producto"); c.gridx = 0; c.gridy = 0; c.gridwidth = 6; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); final JTable table = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Numero"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); modeloTabla.addColumn("Descripcion"); modeloTabla.addColumn("Unidades Disponibles"); modeloTabla.addColumn("Precio"); //LLenar tabla for (int i = 0; i < listaDeProductos.size(); i++) { Object[] data = { "1", "2", "3", "4", "5", "6" }; data[0] = (i + 1); data[1] = listaDeProductos.get(i).getProductoId(); data[2] = listaDeProductos.get(i).getNombre(); data[3] = listaDeProductos.get(i).getDescripcion(); data[4] = listaDeProductos.get(i).getUnidadesDisponibles(); data[5] = listaDeProductos.get(i).getPrecio(); modeloTabla.addRow(data); } table.setModel(modeloTabla); table.getColumn("Numero").setMinWidth(50); table.getColumn("Identificacin").setMinWidth(50); table.getColumn("Nombre").setMinWidth(110); table.getColumn("Descripcion").setMinWidth(110); table.getColumn("Unidades Disponibles").setMinWidth(40); table.getColumn("Precio").setMinWidth(110); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(320, 150)); //final JTable table = new JTable(row, col); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { //jTextField_Factura_Cliente_Id.setText(table.getValueAt(table.getSelectedRow(), 1).toString()); //System.out.println(table.getValueAt(table.getSelectedRow(), 3).toString()); DefaultTableModel modelo = (DefaultTableModel) TablaDeFacturaProducto.getModel(); Object[] fila = new Object[7]; fila[0] = table.getValueAt(table.getSelectedRow(), 0).toString(); fila[1] = table.getValueAt(table.getSelectedRow(), 1).toString(); fila[2] = table.getValueAt(table.getSelectedRow(), 2).toString(); fila[3] = table.getValueAt(table.getSelectedRow(), 3).toString(); //fila[4] = table.getValueAt(table.getSelectedRow(), 4).toString(); fila[4] = (String) JOptionPane.showInputDialog("Ingrese el nmero de unidades que va a vender"); fila[5] = table.getValueAt(table.getSelectedRow(), 5).toString(); Double valorProducto = Double.parseDouble((String) fila[5]); String valorActualProducto = String.valueOf(Double.parseDouble(valorActualFactura.getText()) + Double.parseDouble((String) fila[4]) * valorProducto); valorActualFactura.setText(valorActualProducto); fila[6] = Double.parseDouble((String) fila[4]) * valorProducto; modelo.addRow(fila); //modelo.getColumnName(4). /*TablaDeFacturaProducto.setModel(modelo); TablaDeFacturaProducto.getColumnClass(4). ;*/ dialogoEditar.dispose(); } }); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 200; panelDialogo.add(scroll, c); //panelDialogo.add(table, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void tablaUsuariosDelSistemaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaUsuariosDelSistemaMouseClicked // TODO add your handling code here: String opcionHabilitar = "Habilitar"; String nombreUsuario = String .valueOf(tablaUsuariosDelSistema.getValueAt(tablaUsuariosDelSistema.getSelectedRow(), 0)); String estado = String .valueOf(tablaUsuariosDelSistema.getValueAt(tablaUsuariosDelSistema.getSelectedRow(), 2)); if (estado.equals("Habilitado")) { opcionHabilitar = "Deshabilitar"; }//from w w w. jav a 2s .co m Object[] opciones = { "Cancelar", "Editar", opcionHabilitar }; final ControladorUsuarios controladorUsuarios = new ControladorUsuarios(); final Usuarios usuarioSelecionado = controladorUsuarios.obtenerUsuario(nombreUsuario); if (nombreUsuario.equals("admin") || nombreUsuario.equals(JTextFieldnombreDeUsuario.getText())) { JOptionPane.showMessageDialog(this, "No se puede editarse a si mismo o el usuario administrador del sistema", "Mensaje del sistema", JOptionPane.WARNING_MESSAGE); } else { int opcionElegida = JOptionPane.showOptionDialog(this, "Por favor elija una opcin", "Editar cliente", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opciones, null); switch (opcionElegida) { case 1: final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Editar usuario"); dialogoEditar.setSize(400, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar clientes"); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.insets = new Insets(15, 10, 40, 0); c.ipadx = 0; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 0; JLabel editarNombreClienteDialogo = new JLabel("Login:"); panelDialogo.add(editarNombreClienteDialogo, c); final JTextField valorEditarNombreClienteDialogo = new JTextField(); c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); valorEditarNombreClienteDialogo.setText(usuarioSelecionado.getLogin()); panelDialogo.add(valorEditarNombreClienteDialogo, c); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); JLabel editarPasswordClienteDialogo = new JLabel("Contrasea:"); panelDialogo.add(editarPasswordClienteDialogo, c); final JTextField valoreditarPasswordClienteDialogo = new JTextField(); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); panelDialogo.add(valoreditarPasswordClienteDialogo, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 2; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); JLabel mensajeEditarPassword = new JLabel( "Si no desea editar la contrasea deje este espacio en blanco:"); panelDialogo.add(mensajeEditarPassword, c); c.gridx = 0; c.gridy = 4; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 15, 10, 15); JButton botonGuardarClienteDialogo = new JButton("Guardar"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 4; c.gridwidth = 1; c.insets = new Insets(0, 15, 10, 15); c.ipadx = 0; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String nombreUsuario = valorEditarNombreClienteDialogo.getText(); usuarioSelecionado.setLogin(nombreUsuario); if (!valoreditarPasswordClienteDialogo.getText().equals("")) { usuarioSelecionado.setPassword(valoreditarPasswordClienteDialogo.getText()); } controladorUsuarios.modificarUsuario(usuarioSelecionado.getUser_id(), usuarioSelecionado.getLogin(), usuarioSelecionado.getPassword()); JOptionPane.showMessageDialog(dialogoEditar, "Se ha modificado el usuario con xito", "Mensaje del sistema", JOptionPane.INFORMATION_MESSAGE); generarTablaUsuarios(); dialogoEditar.dispose(); } }); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); break; case 2: if (estado.equals("Habilitado")) { usuarioSelecionado.setStatus('i'); } else { usuarioSelecionado.setStatus('e'); } controladorUsuarios.modificarEstadoUsuario(usuarioSelecionado); JOptionPane.showMessageDialog(this, "Se ha cambiado el estado del usuario", "Mensaje del sistema", JOptionPane.INFORMATION_MESSAGE); generarTablaUsuarios(); break; default: break; } } // TODO add your handling code here: }
From source file:interfaces.InterfazPrincipal.java
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed // TODO add your handling code here: String nombre = jTextFieldNombreSaldoProveedores.getText(); ControladorProveedores controladorProveedores = new ControladorProveedores(); ArrayList<Proveedores> listaProveedores = controladorProveedores.obtenerProveedores("", nombre); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar proveedores"); dialogoEditar.setSize(500, 300);//from w ww . j a v a 2s . com dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Buscar Proveedores"); c.gridx = 0; c.gridy = 0; c.gridwidth = 3; c.insets = new Insets(10, 60, 10, 10); Font textoGrande = new Font("Arial", 1, 16); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); c.gridx = 0; c.gridy = 1; c.gridwidth = 3; c.insets = new Insets(10, 10, 10, 10); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("ID"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); //LLenar tabla for (int i = 0; i < listaProveedores.size(); i++) { Object[] data = { "1", "2", "3" }; data[0] = listaProveedores.get(i).getID(); data[1] = listaProveedores.get(i).getIdentificacion(); data[2] = listaProveedores.get(i).getNombre(); System.out.println("Nombre!!" + data[2]); modeloTabla.addRow(data); } tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("ID").setMinWidth(70); tablaDialogo.getColumn("Identificacin").setMinWidth(60); tablaDialogo.getColumn("Nombre").setMinWidth(150); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(220, 150)); panelDialogo.add(scroll, c); c.insets = new Insets(0, 0, 0, 10); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; JButton botonGuardarClienteDialogo = new JButton("Elegir"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = tablaDialogo.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(dialogoEditar, "Por favor seleccione una fila"); } else { Object identificacionCliente = tablaDialogo.getValueAt(row, 0); Object idCliente = tablaDialogo.getValueAt(row, 1); mostrarIDProveedor.setText(String.valueOf(identificacionCliente)); String nombreClientePago = String.valueOf(tablaDialogo.getValueAt(row, 2)); //Limitar a 15 caracteres if (nombreClientePago.length() >= 15) { nombreClientePago = nombreClientePago.substring(0, 12); } textoNombreProveedor.setText(nombreClientePago); DefaultTableModel modeloClientes = (DefaultTableModel) TablaDeSaldoProveedor.getModel(); for (int i = 0; i < modeloClientes.getRowCount(); i++) { modeloClientes.removeRow(i); } modeloClientes.setRowCount(0); ControladorFlujoCompras controladorFlujoCompra = new ControladorFlujoCompras(); //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506); ArrayList<Flujo_Compra> flujosProveedor = controladorFlujoCompra.obtenerFlujosCompras( " where ID_CompraProveedor in (select ID_CompraProveedor from Compra_Proveedores where IDProveedor = " + String.valueOf(identificacionCliente) + ") order by ID_CompraProveedor"); double pago = 0.0; for (int i = 0; i < flujosProveedor.size(); i++) { Flujo_Compra datos = flujosProveedor.get(i); Object[] rowData = { datos.getID_CompraProveedor(), datos.getTipo_flujo(), datos.getFecha(), datos.getMonto() }; if (datos.getTipo_flujo().equals("deuda")) { pago += Double.parseDouble(datos.getMonto() + ""); } else { pago -= Double.parseDouble(datos.getMonto() + ""); } modeloClientes.addRow(rowData); } TablaDeSaldoProveedor.setModel(modeloClientes); deudaActualProveedor.setText(String.valueOf(pago)); dialogoEditar.dispose(); //Mostrar en table de clientes los datos botonRegistrarAbono.setEnabled(true); } } }); }
From source file:interfaces.InterfazPrincipal.java
private void botonBuscarClienteCrearFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonBuscarClienteCrearFacturaActionPerformed String nombre = nombreClienteCrearFactura.getText(); String identificacion = IdentificacionClienteBuscarFactura.getText(); ControladorCliente controladorCliente = new ControladorCliente(); try {/*from w w w. j a va 2 s. c om*/ int id = 0; if (!identificacion.equals("")) { id = Integer.parseInt(identificacion); } ArrayList<Cliente> listaClientes = controladorCliente.obtenerClientes(nombre, id); if (listaClientes.isEmpty()) { mensajesBusquedaClientesFactura.setText("La busqueda no arrojo resultados"); return; } final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(600, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Buscar Cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); /*Vector col = new Vector(); col.add("1"); col.add("2"); col.add("3"); col.add("4"); Vector row = new Vector(); for (int i = 0; i < listaClientes.size(); i++) { Cliente cliente = listaClientes.get(i); Vector temp = new Vector(); temp.add((i + 1) + ""); temp.add(cliente.getNombre()); temp.add(cliente.getCliente_id() + ""); temp.add(cliente.getMonto_prestamo() + ""); System.out.println("info" + cliente.getNombre() + "," + cliente.getMonto_prestamo()); row.add(temp); } final JTable table = new JTable(row, col); */ final JTable table = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Numero"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); modeloTabla.addColumn("Monto Prestamo"); //LLenar tabla for (int i = 0; i < listaClientes.size(); i++) { Object[] data = { "1", "2", "3", "4" }; data[0] = (i + 1); data[1] = listaClientes.get(i).getCliente_id(); data[2] = listaClientes.get(i).getNombre(); data[3] = listaClientes.get(i).getMonto_prestamo(); modeloTabla.addRow(data); } table.setModel(modeloTabla); table.getColumn("Numero").setMinWidth(50); table.getColumn("Identificacin").setMinWidth(50); table.getColumn("Nombre").setMinWidth(110); table.getColumn("Monto Prestamo").setMinWidth(110); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(320, 150)); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { jTextField_Factura_Cliente_Id.setText(table.getValueAt(table.getSelectedRow(), 1).toString()); String identificacion = table.getValueAt(table.getSelectedRow(), 3).toString(); ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506); ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura( " where factura_id in (select factura_id from Factura where cliente_id = " + String.valueOf(identificacion) + " and estado=\"fiado\") order by factura_id"); double pago = 0.0; for (int i = 0; i < flujosCliente.size(); i++) { String[] datos = flujosCliente.get(i); Object[] rowData = { datos[1], datos[2], datos[3], datos[4] }; if (datos[2].equals("deuda")) { pago += Double.parseDouble(datos[4]); } else { pago -= Double.parseDouble(datos[4]); } } nombreClienteCrearFactura.setText(table.getValueAt(table.getSelectedRow(), 2).toString()); IdentificacionClienteBuscarFactura .setText(table.getValueAt(table.getSelectedRow(), 1).toString()); double montoPrestamo = Double .parseDouble(table.getValueAt(table.getSelectedRow(), 3).toString()); Double totalDisponible = montoPrestamo - pago; valorActualPrestamo.setText(String.valueOf(totalDisponible)); //System.out.println(table.getValueAt(table.getSelectedRow(), 3).toString()); botonAgregarProducto.setEnabled(true); botonGuardarFactura.setEnabled(true); botonEstablecerMontoFactura.setEnabled(true); dialogoEditar.dispose(); } }); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 200; //panelDialogo.add(table, c); panelDialogo.add(scroll, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); } catch (Exception e) { mensajesBusquedaClientesFactura.setText("La identificacion debe ser un numero"); } }
From source file:interfaces.InterfazPrincipal.java
private void BotonBuscarClienteSaldoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonBuscarClienteSaldoActionPerformed String nombreCliente = nombreClienteBusquedaSaldo.getText(); //08-11-2014 listar clientes por nombre ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaClientes = new ArrayList<>(); if (nombreCliente.equals("")) { listaClientes = controladorCliente.obtenerClientes(); } else {/*w w w .j av a 2 s.c o m*/ listaClientes = controladorCliente.obtenerClientes(nombreCliente, 0); } //08-11-2014 Crear dialogo de bsqueda final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(300, 300); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Buscar cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.insets = new Insets(10, 60, 10, 10); Font textoGrande = new Font("Arial", 1, 16); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); c.gridx = 0; c.gridy = 1; c.gridwidth = 2; c.insets = new Insets(10, 10, 10, 10); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); //LLenar tabla for (int i = 0; i < listaClientes.size(); i++) { Object[] data = { "1", "2" }; data[0] = listaClientes.get(i).getCliente_id(); data[1] = listaClientes.get(i).getNombre(); modeloTabla.addRow(data); } tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("Identificacin").setMinWidth(110); tablaDialogo.getColumn("Nombre").setMinWidth(110); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(220, 150)); panelDialogo.add(scroll, c); c.insets = new Insets(0, 0, 0, 10); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; JButton botonGuardarClienteDialogo = new JButton("Elegir"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = tablaDialogo.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(dialogoEditar, "Por favor seleccione una fila"); } else { Object identificacionCliente = tablaDialogo.getValueAt(row, 0); mostrarIdentificacionCliente.setText(String.valueOf(identificacionCliente)); String nombreClientePago = String.valueOf(tablaDialogo.getValueAt(row, 1)); //Limitar a 15 caracteres if (nombreClientePago.length() >= 15) { nombreClientePago = nombreClientePago.substring(0, 12); } textoPersonaSaldo.setText(nombreClientePago); DefaultTableModel modeloClientes = (DefaultTableModel) TablaDeSaldoClientes.getModel(); for (int i = 0; i < modeloClientes.getRowCount(); i++) { modeloClientes.removeRow(i); } modeloClientes.setRowCount(0); ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506); ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura( " where factura_id in (select factura_id from Factura where cliente_id = " + String.valueOf(identificacionCliente) + " and estado=\"fiado\") order by factura_id"); double pago = 0.0; for (int i = 0; i < flujosCliente.size(); i++) { String[] datos = flujosCliente.get(i); TablaDeSaldoClientes.setModel(modeloClientes); NumberFormat formatter = new DecimalFormat("#0"); String valorMovimiento = String.valueOf(formatter.format(Double.parseDouble(datos[4]))); Object[] rowData = { datos[1], datos[2], datos[3], valorMovimiento }; if (datos[2].equals("deuda")) { pago += Double.parseDouble(datos[4]); } else { pago -= Double.parseDouble(datos[4]); } modeloClientes.addRow(rowData); } TablaDeSaldoClientes.setModel(modeloClientes); NumberFormat formatter = new DecimalFormat("#0"); textoTotalDebe.setText(String.valueOf(formatter.format(pago))); dialogoEditar.dispose(); //Mostrar en table de clientes los datos botonRegistrarAbono.setEnabled(true); } } }); }
From source file:interfaces.InterfazPrincipal.java
private void TablaDeProductosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaDeProductosMouseClicked // TODO add your handling code here: int fila = TablaDeProductos.getSelectedRow(); final int identificacion = (int) TablaDeProductos.getValueAt(fila, 1); final ControladorProducto controladorP = new ControladorProducto(); ArrayList<Productos> listaProductos = controladorP.getProducto(" where producto_id = " + identificacion); final Productos productoActual = listaProductos.get(0); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Editar clientes"); dialogoEditar.setSize(600, 310);/*from w w w . ja va 2 s . c o m*/ dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar producto"); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; JLabel editarNombreClienteDialogo = new JLabel("Nombre:"); panelDialogo.add(editarNombreClienteDialogo, c); c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarNombreClienteDialogo = new JTextField(); valorEditarNombreClienteDialogo.setText(productoActual.getNombre()); panelDialogo.add(valorEditarNombreClienteDialogo, c); final JTextField valorEditarUnidadesProductoDialogo = new JTextField(); valorEditarUnidadesProductoDialogo.setText(String.valueOf(productoActual.getUnidadesDisponibles())); panelDialogo.add(valorEditarUnidadesProductoDialogo, c); c.gridx = 2; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 15, 10, 0); JLabel editarTelefonoClienteDialogo = new JLabel("Precio"); panelDialogo.add(editarTelefonoClienteDialogo, c); c.gridx = 3; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 0, 10, 0); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarCelularClienteDialogo = new JLabel("Descripcion:"); panelDialogo.add(editarCelularClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarDescripcionProductoDialogo = new JTextField(); valorEditarDescripcionProductoDialogo.setText(productoActual.getDescripcion()); panelDialogo.add(valorEditarDescripcionProductoDialogo, c); c.gridx = 2; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarMontoClienteDialogo = new JLabel("Unidades"); panelDialogo.add(editarMontoClienteDialogo, c); c.gridx = 3; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarPrecioProductoDialogo = new JTextField(); valorEditarPrecioProductoDialogo.setText(productoActual.getPrecio() + ""); panelDialogo.add(valorEditarPrecioProductoDialogo, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarCodigoBarrasProyecto = new JLabel("Cdigo de barras:"); panelDialogo.add(editarCodigoBarrasProyecto, c); c.gridx = 1; c.gridy = 3; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorCodigoDeBarras = new JTextField(); valorCodigoDeBarras.setText(productoActual.getCodigoBarras()); panelDialogo.add(valorCodigoDeBarras, c); c.gridx = 0; c.gridy = 4; c.gridwidth = 2; c.ipadx = 100; c.insets = new Insets(15, 40, 0, 0); JButton botonGuardarProductoDialogo = new JButton("Guardar"); panelDialogo.add(botonGuardarProductoDialogo, c); c.gridx = 2; c.gridy = 4; c.gridwidth = 2; c.insets = new Insets(15, 40, 0, 0); c.ipadx = 100; JButton botonCerrarProductoDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarProductoDialogo, c); dialogoEditar.add(panelDialogo); botonCerrarProductoDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarProductoDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String[] selection = { "nombre", "descripcion", "unidades", "precio", "codigoBarras" }; String[] value = { valorEditarNombreClienteDialogo.getText(), valorEditarDescripcionProductoDialogo.getText(), valorEditarUnidadesProductoDialogo.getText(), valorEditarPrecioProductoDialogo.getText(), valorCodigoDeBarras.getText() }; String[] type_value = { "varchar", "varchar", "int", "double", "varchar" }; String restriction = " where producto_id = " + identificacion; controladorP.updateProduct(selection, value, type_value, restriction); JOptionPane.showMessageDialog(dialogoEditar, "Se ha editado el producto xitosamente"); dialogoEditar.dispose(); //Refrescar busqueda actual jButton2ActionPerformed(null); } catch (Exception event) { JOptionPane.showMessageDialog(dialogoEditar, "El valor del monto debe ser numrico"); } } }); dialogoEditar.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void TablaDeClientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaDeClientesMouseClicked // TODO add your handling code here: int fila = TablaDeClientes.getSelectedRow(); int identificacion = (int) TablaDeClientes.getValueAt(fila, 0); final ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaClientes = controladorCliente.obtenerClientes("", identificacion); final Cliente clienteActual = listaClientes.get(0); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Editar clientes"); dialogoEditar.setSize(600, 310);//from w w w. java 2 s . com dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar clientes"); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; JLabel editarNombreClienteDialogo = new JLabel("Nombre:"); panelDialogo.add(editarNombreClienteDialogo, c); c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarNombreClienteDialogo = new JTextField(); valorEditarNombreClienteDialogo.setText(clienteActual.getNombre()); panelDialogo.add(valorEditarNombreClienteDialogo, c); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarCelularClienteDialogo = new JLabel("Celular:"); panelDialogo.add(editarCelularClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarCelularClienteDialogo = new JTextField(); valorEditarCelularClienteDialogo.setText(clienteActual.getNumero_celular()); panelDialogo.add(valorEditarCelularClienteDialogo, c); c.gridx = 2; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarMontoClienteDialogo = new JLabel("Monto a prestar:"); panelDialogo.add(editarMontoClienteDialogo, c); c.gridx = 3; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarMontoClienteDialogo = new JTextField(); valorEditarMontoClienteDialogo.setText(String.valueOf(clienteActual.getMonto_prestamo())); panelDialogo.add(valorEditarMontoClienteDialogo, c); c.gridx = 2; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 15, 10, 0); JLabel editarTelefonoClienteDialogo = new JLabel("Telefono:"); panelDialogo.add(editarTelefonoClienteDialogo, c); c.gridx = 3; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 0, 10, 0); final JTextField valorEditarTelefonoClienteDialogo = new JTextField(); valorEditarTelefonoClienteDialogo.setText(clienteActual.getNumero_telefono()); panelDialogo.add(valorEditarTelefonoClienteDialogo, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 0, 10, 0); JLabel editarAddressClienteDialogo = new JLabel("Direccin:"); panelDialogo.add(editarAddressClienteDialogo, c); c.gridx = 1; c.gridy = 3; c.gridwidth = 3; c.ipadx = 400; c.insets = new Insets(0, 15, 10, 0); final JTextField valorEditarAddressClienteDialogo = new JTextField(); valorEditarAddressClienteDialogo.setText(clienteActual.getDireccion()); panelDialogo.add(valorEditarAddressClienteDialogo, c); c.gridx = 0; c.gridy = 4; c.gridwidth = 2; c.ipadx = 100; c.insets = new Insets(15, 40, 0, 0); JButton botonGuardarClienteDialogo = new JButton("Guardar"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 2; c.gridy = 4; c.gridwidth = 2; c.insets = new Insets(15, 40, 0, 0); c.ipadx = 100; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); dialogoEditar.add(panelDialogo); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { clienteActual.setDireccion(valorEditarAddressClienteDialogo.getText()); clienteActual.setMonto_prestamo(Double.parseDouble(valorEditarMontoClienteDialogo.getText())); clienteActual.setNombre(valorEditarNombreClienteDialogo.getText()); clienteActual.setNumero_celular(valorEditarCelularClienteDialogo.getText()); clienteActual.setNumero_telefono(valorEditarTelefonoClienteDialogo.getText()); controladorCliente.editarCliente(clienteActual); JOptionPane.showMessageDialog(dialogoEditar, "Se ha editado el cliente xitosamente"); dialogoEditar.dispose(); //Refrescar busqueda actual String nombreCliente = nombreClienteBusqueda.getText(); int identificacionClienteInt = 0; ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaDeClientes = controladorCliente.obtenerClientes(nombreCliente, identificacionClienteInt); //Agregar filas DefaultTableModel modelo = (DefaultTableModel) TablaDeClientes.getModel(); for (int i = 0; i < modelo.getRowCount(); i++) { modelo.removeRow(i); } modelo.setRowCount(0); for (int i = 0; i < listaDeClientes.size(); i++) { Cliente cliente = listaDeClientes.get(i); Object[] fila = new Object[4]; fila[0] = cliente.getCliente_id(); fila[1] = cliente.getNombre(); fila[2] = cliente.getMonto_prestamo(); //button.setText("<HTML>Click the <FONT color=\"#000099\"><U>link "+i+"</U></FONT>"+ " to go to the Java website.</HTML>"); fila[3] = "Editar"; modelo.addRow(fila); } TablaDeClientes.setModel(modelo); } catch (Exception event) { JOptionPane.showMessageDialog(dialogoEditar, "El valor del monto debe ser numrico"); } } }); dialogoEditar.setVisible(true); /*Action mostrarMensaje; mostrarMensaje = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); ((DefaultTableModel) table.getModel()).removeRow(modelRow); } }; ButtonColumn buttonColumn = new ButtonColumn(TablaDeClientes, mostrarMensaje, 3); buttonColumn.setMnemonic(KeyEvent.VK_E);*/ }