Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
Why does switch only show default output in console and *not* in the actual application?

I'm making my first java desktop application (which explains the lack of knowledge), when I run the project, the default output comes in the console instead of the actual project, wheras when the field is filled in correctly, it shows the output on the application/project.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String name = textBoxName.getText();
    switch (textBoxName.getText()) {
        case "":
            System.out.println("Name field cannot be blank!");
            break;
        default:
            Message.setText(name);         
    }
}
    
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Using System.out.println("your message here"); you are writing in the console, which is usually used to debug things. If you want to show the message to the user in a GUI interface, there is an useful class in Swing. Instead of System.out.println(); try

JOptionPane.showMessageDialog(null, "Name field cannot be blank!");

which will create a dialog with your message inside it and a button to close it. You can also specify a title of the dialog and the type of dialog like this:

JOptionPane.showMessageDialog(null, "Name field cannot be blank!", "Title of the message", JOptionPane.PLAIN_MESSAGE);

where instead of JOptionPane.PLAIN_MESSAGE you can also put ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE or QUESTION_MESSAGE.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda