{"id":4294,"date":"2017-09-20T11:04:00","date_gmt":"2017-09-20T11:04:00","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=4294"},"modified":"2021-03-21T06:27:11","modified_gmt":"2021-03-21T06:27:11","slug":"how-to-make-dialog-in-a-java-program-joptionpane","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/how-to-make-dialog-in-a-java-program-joptionpane\/","title":{"rendered":"How to make Dialog in a Java Program using JOptionPane?"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>JOptionPane is used for the dialog box that prompts users for a value or informs them in a Java program. Most of the methods in the JOptionPane are of showXXDialog<\/p>\n<p>For example:<\/p>\n<p>showInputDialog -&gt; To prompt user for some input.<\/p>\n<p>showMessageDialog-&gt; To tell the user about something.<\/p>\n<p>More information: <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JOptionPane.html\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JOptionPane.html<\/a><\/p>\n<h3>Code Listing<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import javax.swing.JOptionPane;\r\n\r\npublic class DialogDemo {\r\n\r\n  \/\/***** Main method  *****\/\/\r\n  public static void main(String[] args) {\r\n    String message=\"Hello World\";\r\n    JOptionPane.showMessageDialog(null,message);\r\n  }\r\n}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4301\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/JOptionPane-Dialog.png\" alt=\"JOptionPane Dialog\" width=\"1733\" height=\"779\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/JOptionPane-Dialog.png 1733w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/JOptionPane-Dialog-300x135.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/JOptionPane-Dialog-1024x460.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/JOptionPane-Dialog-768x345.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/JOptionPane-Dialog-1536x690.png 1536w\" sizes=\"auto, (max-width: 1733px) 100vw, 1733px\" \/><\/p>\n<h3><\/h3>\n<h3>Taking input<\/h3>\n<p>A simple program to take input from the user:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import javax.swing.JOptionPane;\r\n\r\npublic class DialogDemo {\r\n\r\n  \/\/***** Main method  *****\/\/\r\n  public static void main(String[] args) {\r\n    String input = \"\"; \/\/blank\r\n    input= JOptionPane.showInputDialog(null);\r\n        System.out.println(\"You entered = \"+ input);\r\n  }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4304\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InputDialog-JOptionPane.png\" alt=\"\" width=\"1726\" height=\"760\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InputDialog-JOptionPane.png 1726w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InputDialog-JOptionPane-300x132.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InputDialog-JOptionPane-1024x451.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InputDialog-JOptionPane-768x338.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InputDialog-JOptionPane-1536x676.png 1536w\" sizes=\"auto, (max-width: 1726px) 100vw, 1726px\" \/><\/p>\n<p>&nbsp;<\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-4294\" data-postid=\"4294\" class=\"themify_builder_content themify_builder_content-4294 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Introduction JOptionPane is used for the dialog box that prompts users for a value or informs them in a Java program. Most of the methods in the JOptionPane are of showXXDialog For example: showInputDialog -&gt; To prompt user for some input. showMessageDialog-&gt; To tell the user about something. More information: https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JOptionPane.html Code Listing import javax.swing.JOptionPane; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-4294","post","type-post","status-publish","format-standard","hentry","category-java","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/4294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=4294"}],"version-history":[{"count":3,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/4294\/revisions"}],"predecessor-version":[{"id":19729,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/4294\/revisions\/19729"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=4294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=4294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=4294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}