Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

237
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda