Quick Answer

Display message dialogs in Java.

Understanding the Issue

Swing provides JOptionPane for simple dialog boxes. For JavaFX, use Alert class. Both are thread-sensitive and require proper EDT handling.

The Problem

This code demonstrates the issue:

Java Error
// Need to show alert message

The Solution

Here's the corrected code:

Java Fixed
// Swing solution
import javax.swing.JOptionPane;

// Basic message
JOptionPane.showMessageDialog(null, "Hello World");

// Warning dialog
JOptionPane.showMessageDialog(null, 
    "Warning message", 
    "Warning",
    JOptionPane.WARNING_MESSAGE);

// JavaFX solution
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Message");
alert.setHeaderText(null);
alert.setContentText("Hello World!");
alert.showAndWait();

Key Takeaways

Use JOptionPane for Swing, Alert for JavaFX.