예제 #1
0
  public void valueChanged(ListSelectionEvent e) {
    int maxRows;
    int[] selRows;
    Object value;

    if (!e.getValueIsAdjusting()) {
      selRows = aTable.getSelectedRows();

      if (selRows.length > 0) {
        for (int i = 0; i < 3; i++) {
          // get Table data
          TableModel tm = aTable.getModel();
          value = tm.getValueAt(selRows[0], i);
          System.out.println("Selection : " + value);
        }
        System.out.println();
      }
    }
  }
예제 #2
0
 /** Overrides <code>JComponent</code>'s <code>getToolTipText</code> */
 public String getToolTipText(MouseEvent e) {
   String tip = null;
   java.awt.Point p = e.getPoint();
   int rowIndex = rowAtPoint(p);
   // int colIndex = columnAtPoint(p);
   // int realColumnIndex = convertColumnIndexToModel(colIndex);
   TableModel model = getModel();
   tip = (String) model.getValueAt(rowIndex, 1);
   return tip;
 }
예제 #3
0
  public void calculaSumas() {
    try {
      TableModel tm = this.tablaPrincipal.getModel();
      int tamTabla = tm.getRowCount();
      double costo, cantidad, totalFila, sumaTotal;
      sumaTotal = 0.0;

      for (int i = 0; i < tamTabla; i++) {
        if (tm.getValueAt(i, 2) != null && tm.getValueAt(i, 3) != null) {
          costo = Double.valueOf(String.valueOf(tm.getValueAt(i, 2)));
          cantidad = Double.valueOf(String.valueOf(tm.getValueAt(i, 3)));
          totalFila = costo * cantidad;

          tm.setValueAt(totalFila, i, 4);
          sumaTotal += totalFila;
        }
      }

      txtSumaTotal.setText(String.valueOf(sumaTotal));
    } catch (Exception e) {
      Dialogos.lanzarAlerta("Cantidades invalidas, puede que algun numero este mal escrito");
    }
  }
예제 #4
0
 /**
  * Return a label for the given point on the graph axis
  *
  * @param value the value on the graph
  * @return the label for the given value
  */
 private String getLeafLabel(double value) {
   String label = Double.toString(value);
   try {
     int v = (int) value;
     int r = idxMap.getSrc(v);
     if (r < 0 || r >= tm.getRowCount()) {
       return "";
     }
     if (labelColumn >= 0 && labelColumn < tm.getColumnCount()) {
       Object o = tm.getValueAt(r, labelColumn);
       return o != null ? o.toString() : "";
     }
   } catch (Exception ex) {
     ExceptionHandler.popupException("" + ex);
   }
   try {
     label = Integer.toString((int) value);
   } catch (Exception ex) {
     ExceptionHandler.popupException("" + ex);
   }
   return label;
 }
예제 #5
0
      public void tableChanged(TableModelEvent tme) {
        int baris = tme.getFirstRow();
        int kolom = tme.getColumn();

        TableModel model = (TableModel) tme.getSource();
        int id = (Integer) model.getValueAt(baris, 0);

        String query = "";
        switch (kolom) {
          case 1:
            String nama = (String) model.getValueAt(baris, kolom);
            query = "UPDATE produk SET nama_produk='" + nama + "' WHERE id_produk=" + id;
            prosesEdit(query);
            break;
          case 2:
            String jenis = (String) model.getValueAt(baris, kolom);
            try {
              query = "select * from jenis where nama_jenis='" + jenis + "'";
              ResultSet rs = stm.executeQuery(query);
              if (rs.next()) {
                int idJenis = rs.getInt("id_jenis");
                query = "UPDATE produk SET id_jenis=" + idJenis + " WHERE id_produk=" + id;
                prosesEdit(query);
              } else {
                setDataTabel();
                JOptionPane.showMessageDialog(null, "gagal,jenis tidak ada");
              }
            } catch (SQLException SQLerr) {
              SQLerr.printStackTrace();
            }
            break;
          case 3:
            int stok = (Integer) model.getValueAt(baris, kolom);
            query = "UPDATE `stok_produk` SET stok=" + stok + " WHERE id_produk=" + id;
            prosesEdit(query);
            break;
          case 4:
            int harga = (Integer) model.getValueAt(baris, kolom);
            query = "UPDATE produk SET harga=" + harga + " WHERE id_produk=" + id;
            prosesEdit(query);
            break;
          case 5:
            String suplier = (String) model.getValueAt(baris, kolom);
            try {
              query = "SELECT * FROM suplier WHERE nama_suplier='" + suplier + "'";
              ResultSet rs = stm.executeQuery(query);
              if (rs.next()) {
                int idSuplier = rs.getInt("id_suplier");
                query = "UPDATE produk SET id_suplier=" + idSuplier + " WHERE id_produk=" + id;
                prosesEdit(query);
              } else {
                setDataTabel();
                JOptionPane.showMessageDialog(null, "gagal,suplier belum terdaftar");
              }
            } catch (SQLException SQLerr) {
              SQLerr.printStackTrace();
            }
            break;
          default:
            break;
        }
      }
예제 #6
0
 public Object getValueAt(int row, int column) {
   return tableModel.getValueAt(modelIndex(row), column);
 }