Warum muss man bei Java bei JOptionPane.showMessageDialog( null, angeben?

3 Antworten

Der erste Parameter könnte ein Parent Frame sein. Da das OptionPane ja Modal ist, könnte man damit ein anderes Element Sperren wie z.B. eine Eingabe-Maske, sodass während der Dialog offen ist, keine Eingabe in die andere Maske möglich ist.

Gibt man "null" an, wird kein anderes Element blockiert oder gesperrt, während der Dialog offen ist.

Der erste Parameter ist lt. Dokumentation folgendes:

parentComponent
Defines the  Component that is to be the parent of this dialog box. It is used in two ways: the  Frame that contains it is used as the  Frame parent for the dialog box, and its screen coordinates are used in the placement of the dialog box. In general, the dialog box is placed just below the component. This parameter may be  null, in which case a default  Frame is used as the parent, and the dialog will be centered on the screen (depending on the L&F).

MUSS als nicht null sein, kann aber halt ;)

Woher ich das weiß:Studium / Ausbildung – Informatikstudium

Null heißt soviel wie Nichst oder Kein Wert.
Wenn du Beispielsweise eine Variable erstellst und dieser keinen Wert zuweist, dann ist diese Variable automatisch null, also kein Wert(oder  nicht definiert).

showMessageDialoge ist eine Methode die (glaube ich) 2 Instanzen benötigt, muss in der ersten, in diesem Fall eine Klasse rein, lange Rede kurzer Sinn, du schreibst da Null rein.