Bom dia, pessoal estou com uns probleminhas no meu código, acredito que é simples, já vi varios materiais, tutoriais, artigos, mas nenhum me ajudou muito.
Estou utilizando um jCombobox para listar os produtos do estoque, quero fazer de uma forma que quando digitar uma letra ele vá completando a palavra e se errar, ele corrija, no final, quero pressionar enter e fazer com que ele carregue na tela de vendas os campos id, quantidade, valor, valor mínimo, etc.
Obs: A conexão está perfeita e está lisatando normalmente, o problema são só esses dois.
Alguém pode me ajudar?
aí vai o código:
private void pressed(KeyEvent evt) {
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
Object a = evt.getSource();
if (a.equals(jComboBox3)) {
// jComboBox3.requestFocus();
try {
rs = new dao.Produto().buscarProduto(jComboBox3.getToolTipText());
} catch (SQLException ex) {
Logger.getLogger(Vender.class.getName()).log(Level.SEVERE, null, ex);
}
if (rs != null) {
jComboBox3.setToolTipText(rs.getDescricao() + " - " + rs.getMarca() + " - " + rs.getFabricante());
jTextField7.setText(rs.getVenda());
jFormattedTextField3.setText("1");
jTextField10.setText(rs.getEstoqueatual());
jTextField11.setText(rs.getValorminimo());
jTextField6.setText(rs.getCodbarras());
} else {
jTextField6.setText("");
jTextField7.setText("");
jFormattedTextField3.setText("");
JOptionPane.showMessageDialog(rootPane, "Produto não Cadastrado!");
jComboBox3.setToolTipText("");
jTextField10.setText("");
}
} else {
if (a.equals(jFormattedTextField3)) {
} else {
if (a.equals(jTextField8)) {
} else {
}
}
}
}
if (evt.getKeyCode() == KeyEvent.VK_F2) {
if (caixa) {
if (Integer.parseInt(jFormattedTextField3.getText().trim()) <= Integer.parseInt(rs.getEstoqueatual())) {
if (jComboBox3.getToolTipText().trim().length() > 0) {
Object dados[] = new Object[6];
String valor = rs.getVenda();
dados[0] = k;
dados[1] = rs.getCodbarras();
dados[2] = rs.getDescricao() + " - " + rs.getMarca() + " - " + rs.getFabricante();
dados[4] = jFormattedTextField3.getText();
++k;
String valor4 = "0";
boolean test = true;
String a[] = jTextField8.getText().split(",");
String Valor = "0.00";
if(a.length == 2){
Valor = a[0]+"."+a[1];
}else{
Valor = a[0];
}
valorgeral += (((Integer.parseInt(jFormattedTextField3.getText().trim())) * (Double.parseDouble(valor))));
double valor2 = Double.parseDouble(valor);
double valorunit = 0.0;
valorunit = Double.parseDouble(jTextField7.getText());
double valor7 = 0.0;
if(){Valor.equals("")
}else{
valor7 = Double.parseDouble(Valor);
valorgeral = desconto(valorgeral, valor7);
}
DecimalFormat dec = new DecimalFormat("########.00");
String s = dec.format(valorgeral);
String s2 = dec.format(valorunit);
dados[3] = s2;
dados[5] = dec.format(((Integer.parseInt(jFormattedTextField3.getText().trim()) * valorunit)-valor7));
jTextField9.setText(s);
((DefaultTableModel) jTable1.getModel()).addRow(dados);
jTextField8.requestFocus();
try {
new dao.Produto().alterarestoque(Integer.parseInt(jTextField10.getText()), Integer.parseInt(jFormattedTextField3.getText().trim()), rs.getId());
} catch (SQLException ex) {
Logger.getLogger(Vender.class.getName()).log(Level.SEVERE, null, ex);
}
}
limpar();
} else {
JOptionPane.showMessageDialog(this, "O estoque so possui " + rs.getEstoqueatual() + " peças");
}
}
}
if (evt.getKeyCode() == KeyEvent.VK_F3) {
if (caixa) {
if (k > 0) {
String valor = JOptionPane.showInputDialog(this, "Digite o id a ser deletado:");
int valor2 = Integer.parseInt(valor);
try {
rs = new dao.Produto().buscarProduto((String) jTable1.getModel().getValueAt(valor2, 1));
} catch (SQLException ex) {
Logger.getLogger(Vender.class.getName()).log(Level.SEVERE, null, ex);
}
String valor4 = rs.getEstoqueatual();
int id2 = rs.getId();
String valor3 = (String) jTable1.getModel().getValueAt(valor2, 4);
try {
new dao.Produto().alterarestoquemenos(Integer.parseInt(valor4.trim()), Integer.parseInt(valor3.trim()), id2);
} catch (SQLException ex) {
Logger.getLogger(Vender.class.getName()).log(Level.SEVERE, null, ex);
}
String a = (String) jTable1.getModel().getValueAt(valor2, 5);
String b = "";
for (int i = 0; i < a.trim().length(); i++) {
if (a.charAt(i) == ',') {
b += ".";
} else {
b += a.charAt(i);
}
}
Double d = Double.parseDouble(b);
String c = jTextField9.getText();
b = "";
for (int i = 0; i < c.trim().length(); i++) {
if (c.charAt(i) == ',') {
b += ".";
} else {
b += c.charAt(i);
}
}
Double e = Double.parseDouble(b.trim());
Double f = e - d;
DecimalFormat dec = new DecimalFormat("########.00");
String s = dec.format(f);
jTextField9.setText(s);
((DefaultTableModel) jTable1.getModel()).removeRow(valor2);
--k;
for (int i = 0; i < k; i++) {
jTable1.setValueAt(Integer.toString(i), i, 0);
}
jComboBox3.requestFocus();
}
}
}
//Código de
if (evt.getKeyCode() == KeyEvent.VK_F4) {
if (k > 0) {
} else {
if (caixa) {
} else {
dispose();
}
}
}
if (evt.getKeyCode() == KeyEvent.VK_F5) {
if (caixa) {
if (k > 0) {
ConcluirVenda con = new ConcluirVenda(this);
con.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
con.setLocationRelativeTo(null);
con.setVisible(true);
}
}
}
if (evt.getKeyCode() == KeyEvent.VK_F6) {
if (!caixa) {
caixa = true;
JOptionPane.showMessageDialog(this, "Caixa aberto");
}
}
if (evt.getKeyCode() == KeyEvent.VK_F7) {
if (caixa) {
int inty = JOptionPane.showConfirmDialog(this, "Tem certeza que deseja fechar o caixa");
if (inty == 0) {
if (k > 0) {
} else {
caixa = false;
Vendas1 login;
try {
login = new Vendas1();
login.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
login.setLocationRelativeTo(null);
login.setVisible(true);
} catch (SQLException ex) {
Logger.getLogger(Vender.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}