Add one more check, how to proceed?

Asked

Viewed 70 times

-4

I would like to know how to add 1 more check. I would like to have row 31 checked as well. Example:

Object obj2 = modelo.getValueAt(linha, 31);

In this code here.

else if (snreferencia.contains("Sim")) {
    Object obj = modelo.getValueAt(linha, 30);

    if (obj == null || obj.toString().trim().isEmpty()) {
        modelo.setValueAt("", linha, 33);
    } else {
        modelo.setValueAt("Referência", linha, 33);
    }
}

I tried to do it that way, but I couldn’t

else if (snreferencia.contains("Sim")) {
    Object obj = modelo.getValueAt(linha, 30);
    Object obj2 = modelo.getValueAt(linha, 31);
    if (obj == null || obj.toString().trim().isEmpty()) {
        modelo.setValueAt("", linha, 33);
    }
    if (obj2 == null || obj2.toString().trim().isEmpty()) {
        modelo.setValueAt("", linha, 33);
    } else {
        modelo.setValueAt("Referência", linha, 33);
    }
}

as it is currently

    public void VerificarResultdoEnter() {
        int linha = tabela1.getSelectedRow() -1;
        int coluna = tabela1.getSelectedColumn();
        String tipo = tabela1.getValueAt(linha, 26).toString();
        String snreferencia = tabela1.getValueAt(linha, 21).toString();
        if (tipo.contains("Texto") && !snreferencia.contains("Sim")) {

            String valor1 = tabela1.getValueAt(linha, 27).toString(); //Especificacao
            String valor2 = tabela1.getValueAt(linha, 31).toString(); //Valor digitado pelo usuario  
            if (valor1.equals(valor2)) {
                modelo.setValueAt("Aprovado", linha, 33);
//                modelo.isCellEditable(linha, 32);
            } else {
                modelo.setValueAt("Reprovado", linha, 33);
            }
            Object obj = modelo.getValueAt(linha, 31);
            if (obj == null || obj.toString().trim().isEmpty()) {
                modelo.setValueAt("", linha, 33);
            }
        } else if (tipo.contains("Min e Max") && !snreferencia.contains("Sim")) {
            Object obj = modelo.getValueAt(linha, 30);
            if (obj == null || obj.toString().trim().isEmpty()) {
                modelo.setValueAt("", linha, 33);
            }
            Float valornumerico = Float.parseFloat(modelo.getValueAt(linha, 30).toString()); //Valor digitado pelo usuario   
            if (valornumerico >= Float.parseFloat(modelo.getValueAt(linha, 17).toString()) && valornumerico <= Float.parseFloat(modelo.getValueAt(linha, 18).toString())) {
                modelo.setValueAt("Aprovado", linha, 33);
            } else {
                modelo.setValueAt("Reprovado", linha, 33);
//                modelo.isCellEditable(linha, 32);
            }
        } else if (tipo.contains("No Min") && !snreferencia.contains("Sim")) {
            Object obj = modelo.getValueAt(linha, 30);
            if (obj == null || obj.toString().trim().isEmpty()) {
                modelo.setValueAt("", linha, 33);
            }
            Float valornumerico = Float.parseFloat(modelo.getValueAt(linha, 30).toString()); //Valor digitado pelo usuario   
            if (valornumerico >= Float.parseFloat(modelo.getValueAt(linha, 17).toString())) {
                modelo.setValueAt("Aprovado", linha, 33);
            } else {
                modelo.setValueAt("Reprovado", linha, 33);
//                modelo.isCellEditable(linha, 32);
            }
        } else if (tipo.contains("No Max") && !snreferencia.contains("Sim")) {
            Object obj = modelo.getValueAt(linha, 30);
            if (obj == null || obj.toString().trim().isEmpty()) {
                modelo.setValueAt("", linha, 33);
            }
            Float valornumerico = Float.parseFloat(modelo.getValueAt(linha, 30).toString()); //Valor digitado pelo usuario   
            if (valornumerico <= Float.parseFloat(modelo.getValueAt(linha, 18).toString())) {
                modelo.setValueAt("Aprovado", linha, 33);
            } else {
                modelo.setValueAt("Reprovado", linha, 33);
//                modelo.isCellEditable(linha, 32);
            }
        } else if (tipo.contains("ValorUnico") && !snreferencia.contains("Sim")) {
            Object obj = modelo.getValueAt(linha, 30);
            if (obj == null || obj.toString().trim().isEmpty()) {
                modelo.setValueAt("", linha, 33);
            }
            Float valornumerico = Float.parseFloat(modelo.getValueAt(linha, 30).toString()); //Valor digitado pelo usuario 
            if (valornumerico == Float.parseFloat(modelo.getValueAt(linha, 17).toString())) {
                modelo.setValueAt("Aprovado", linha, 33);
            } else {
                modelo.setValueAt("Reprovado", linha, 33);
//                modelo.isCellEditable(linha, 32);
            }
        } else if (snreferencia.contains("Sim")) {
            Object obj = modelo.getValueAt(linha, 30);
            if (obj == null || obj.toString().trim().isEmpty()) {
                modelo.setValueAt("", linha, 33);
            } else {
                modelo.setValueAt("Referência", linha, 33);
            }

        }
    }

the way it is, it’s working fine, but I’m just having a problem..

else if (snreferencia.contains("Sim")) {
    Object obj = modelo.getValueAt(linha, 30);

    if (obj == null || obj.toString().trim().isEmpty()) {
        modelo.setValueAt("", linha, 33);
    } else {
        modelo.setValueAt("Referência", linha, 33);
    }
}

I tried to include to check the 31 column, but he either checks the 31 or checks the 30, I’m able to put the 2, if you can help me, I appreciate.

  • Verified what? Where? Add a [mcve], your doubt is not clear.

  • I would just like to know how to include this second line

  • 3

    This smells like a tablemodel scam. But if you don’t provide a [mcve] of it is difficult to analyze something.

  • 1

    There’s no way I taught you how to gambiarra, hardly any useful. Gambiarra is just a way around something you don’t quite understand how to do it the right way. And I have no idea what that code does, it doesn’t make any sense to me.

  • Related: https://answall.com/q/227074/132

  • 2

    In your other question, I even started trying to formulate an answer, but I gave up because the question had so many holes in it that I didn’t think it would amount to anything. That other question of yours is far worse.

  • wow @Victorstafusa!

  • 2

    @Rafaelchaves Your question is very bad and for me it would be closed because it is not clear enough. In the meantime, I’ve decided to post an answer anyway to see if it helps you at least explain better what your problem is.

  • 3

    Do you see? It is no use throwing a piece of code and waiting for someone to turn to understand, it is not for no reason that you have accumulated so many negative votes in your questions, they are almost incomprehensible. Always strive to provide a clear question and code that makes sense and, above all, that is testable, so you will surely get solutions faster. I recommend that read here to see what should be avoided by asking a question.

  • Good morning @Victorstafusam, This is basically what I want, but the problem I’m suffering is with the result "null" as I posted this code ah some time, I made some changes and I’ll post to you see how it turned out. But I really appreciate your help!

Show 5 more comments

1 answer

2

First, simplify your method by eliminating redundancies. Considering the your previous question, I think it looks something like this:

public void verificarResultado() {
    int linha = cadastroResultadoTabela.getSelectedRow();
    int coluna = cadastroResultadoTabela.getSelectedColumn();
    String tipo = cadastroResultadoTabela.getValueAt(linha, 26).toString();
    boolean snReferencia = cadastroResultadoTabela.getValueAt(linha, 21).toString().contains("Sim");

    if (snReferencia) {
        modelo.setValueAt("Referência", linha, 33);
        return;
    } 

    float valorNumerico = Float.parseFloat(cadastroResultadoTabela.getValueAt(linha, 30).toString()); // Valor digitado pelo usuario
    String valor1 = cadastroResultadoTabela.getValueAt(linha, 27).toString(); //Especificacao
    String valor2 = cadastroResultadoTabela.getValueAt(linha, 31).toString(); //Valor digitado pelo usuario
    float valorA = Float.parseFloat(cadastroResultadoTabela.getValueAt(linha, 17).toString());
    float valorB = Float.parseFloat(cadastroResultadoTabela.getValueAt(linha, 18).toString());

    boolean aprovado
            = tipo.contains("Texto") ? valor1.equals(valor2)
            : tipo.contains("Min e Max") ? valorNumerico >= valorA && valorNumerico <= valorB
            : tipo.contains("No Min") ? valorNumerico >= valorA
            : tipo.contains("No Max") ? valorNumerico <= valorB
            : tipo.contains("ValorUnico") ? valorNumerico == valorA
            : true;

    if (aprovado) {
        modelo.setValueAt("Aprovado", linha, 33);
    } else {
        modelo.setValueAt("Reprovado", linha, 33);
        modelo.isCellEditable(linha, 32);
    }
}

You can then change the condition of the variable aprovado to include something from row 31 as well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.