[Java] Show message dialog in java (memo note)

1 minute read

I was enthusiastic and didn’t post in just the first day… Promptly, but I will post it as a memo for myself. Usually, I do not code it in java, so I will list the results of various investigations without knowing how to open the dialog.

Difference between # awt and swing As mentioned above, I usually don’t touch java at all, and I rarely work with GUI programs, so I start here. I knew the names of awt and swing and how they were used, but I didn’t understand the difference. (In addition, JavaFX is also mentioned.)

  • AWT is available for all Java versions and has the advantage of working with any Java runtime.
  • Inherit AWT, eliminate the drawback of AWT “The appearance of GUI depends on the platform”, and eliminate the lack of extensibility
  • JavaFx: You can use XML and CSS together to describe the design, and separate the design creation from the processing class description.

I have referred to the following article.

Show the dialog using # java.awt As far as I’ve checked, it feels a little messy. I just want to use something like the MsgBox function in VBA.

  • import java.awt
  • Instance generation of Dialog class, generation of dialog
  • Specify size with dialog.setSize
  • Show dialog with dialog.setVisible
  • Processing to close the frame if necessary
  • Create a java.awt.Dialog dialog ← This article was referenced.

Show dialog using # swing Just import javax.swing.JOptionPane and call JOptionPane.showMessageDialog. I didn’t want to spend time and I chose this for my app. Code omitted.

I referred to the following article.