コード例 #1
0
ファイル: FrmNotaAddItem.java プロジェクト: ustadho/tpj-keu
  private void formWindowOpened(
      java.awt.event.WindowEvent evt) { // GEN-FIRST:event_formWindowOpened
    lst = new ListRsbm();
    lst2 = new ListRsbmNota();

    lst.setVisible(false);
    lst.setSize(500, 200);
    lst.con = conn;

    lst2.setVisible(false);
    lst2.setSize(500, 200);
    lst2.con = conn;

    MyKeyListener kListener = new MyKeyListener();
    for (int i = 0; i < jPanel1.getComponentCount(); i++) {
      Component c = jPanel1.getComponent(i);
      if (c.getClass().getSimpleName().equalsIgnoreCase("JTEXTFIELD")
          || c.getClass().getSimpleName().equalsIgnoreCase("JFormattedTextField")
          || c.getClass().getSimpleName().equalsIgnoreCase("JTextArea")
          || c.getClass().getSimpleName().equalsIgnoreCase("JComboBox")
          || c.getClass().getSimpleName().equalsIgnoreCase("JButton")
          || c.getClass().getSimpleName().equalsIgnoreCase("JCheckBox")
          || c.getClass().getSimpleName().equalsIgnoreCase("JRadioButton")) {
        // System.out.println(c.getClass().getSimpleName());
        c.addKeyListener(kListener);
      }
    }
  } // GEN-LAST:event_formWindowOpened
コード例 #2
0
ファイル: FrmNotaAddItem.java プロジェクト: ustadho/tpj-keu
  private void txtItemTrxKeyReleased(
      java.awt.event.KeyEvent evt) { // GEN-FIRST:event_txtItemTrxKeyReleased
    if (txtItemTrx.getText().trim().equalsIgnoreCase("")) {
      return;
    }
    String sQry;

    try {
      // String sCari = txtKepada.getText();
      switch (evt.getKeyCode()) {
        case java.awt.event.KeyEvent.VK_ENTER:
          {
            if (lst2.isVisible()) {
              Object[] obj = lst2.getOResult();
              if (obj.length > 0) {
                txtItemTrx.setText(obj[0].toString());
                lst2.setVisible(false);
              }
            }
            break;
          }
        case java.awt.event.KeyEvent.VK_DELETE:
          {
            lst2.setFocusable(true);
            lst2.requestFocus();

            break;
          }
        case java.awt.event.KeyEvent.VK_ESCAPE:
          {
            lst2.setVisible(false);
            txtItemTrx.setText("");

            break;
          }

        case java.awt.event.KeyEvent.VK_DOWN:
          {
            if (lst2.isVisible()) {

              lst2.setFocusableWindowState(true);
              lst2.setVisible(true);
              lst2.requestFocus();
            }
            break;
          }
        default:
          {
            if (!evt.getKeyText(evt.getKeyCode()).equalsIgnoreCase("Up")
                || !evt.getKeyText(evt.getKeyCode()).equalsIgnoreCase("F2")) {

              sQry =
                  "select distinct item_trx from nota_item_trx where item_trx iLike '%"
                      + txtItemTrx.getText()
                      + "%' order by 1 ";

              //
              System.out.println(sQry);
              lst2.setSQuery(sQry);

              lst2.setBounds(
                  this.getX() + this.jPanel1.getX() + this.txtItemTrx.getX() + 3,
                  this.getY()
                      + this.jPanel1.getY()
                      + this.txtItemTrx.getY()
                      + txtItemTrx.getHeight()
                      + 30,
                  txtItemTrx.getWidth(),
                  100);
              lst2.setFocusableWindowState(false);
              lst2.setTxtCari(txtItemTrx);
              lst2.setLblDes(new javax.swing.JLabel[] {});
              lst2.setColWidth(0, txtItemTrx.getWidth());

              if (lst2.getIRowCount() > 0) {
                lst2.setVisible(true);
                requestFocusInWindow();
                txtItemTrx.requestFocus();
              } else {
                lst2.setVisible(false);
                // txtKepada.setText("");
                txtItemTrx.requestFocus();
              }
            }
            break;
          }
      }
    } catch (SQLException se) {
      System.out.println(se.getMessage());
    }
  } // GEN-LAST:event_txtItemTrxKeyReleased