Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Java Programming > Java GUI สอน Java GUI เขียนโปรแกรม GUI ด้วย Java(Swing/AWT/JFC) > พื้นฐาน Form การสร้าง Dialog MessageBox บน Java GUI เพื่อโต้ตอบกับผู้ใช้



Clound SSD Virtual Server

พื้นฐาน Form การสร้าง Dialog MessageBox บน Java GUI เพื่อโต้ตอบกับผู้ใช้

พื้นฐาน Form การสร้าง Dialog Message Box บน Java GUI เพื่อโต้ตอบกับผู้ใช้ ในการใช้งาน Dialog หรือ MessagBox บน Java GUI ถือว่าเป็นหัวข้อหนึ่งที่เราจะต้องสนใจอย่างยิ่ง เพราะมันจำเป็นจะต้องนำไปใช้กับการเขียนโปแกรมบน Form อย่างแน่นอน และ Dialog หรือ MessagBox ก็มีให้เลือกใช้งานได้หลานชนิด ตามประเภทของ Message เช่น เป็นแค่ Information แจ้งให้ทราบ , Warning หรือ Error และนอกจากนี้ยังมี MessagBox ที่ทำหน้าที่เป็น Input และ Optional Conform Dialog ได้อีกด้วย

Java GUI Dialog MessageBox

Java GUI Dialog MessagBox ประเภทของ Dialog MessageBox


ในการใช้งาน Dialog หรือ MessagBox บน Java GUI เราจะใช้ Class ของ JOptionPane (javax.swing.JOptionPane) และมี Property อาทิเช่น showMessageDialog , showOptionDialog และอื่น ๆ รวมทั้งมี Argument ที่รอรับ Parameters ที่สามารถกำหนดรูปแบบของ Dialog ได้อย่างหลากหลาย

อ่านบทความเกี่ยวกับการสร้าง Dialog MessageBox แบบง่าย ๆ

Eclipse : สร้าง Java GUI และการสร้าง Event Action และ Dialog โต้ตอบแบบง่าย ๆ

Netbeans : สร้าง Java GUI และการสร้าง Event Action และ Dialog โต้ตอบแบบง่าย ๆ

พื้นฐาน Java สร้าง Controls บน GUI และการสร้าง Action Event Handler กับ Controls


ตัวอย่างชนิดของ Dialog แบบต่าง ๆ

		JOptionPane.showMessageDialog(null,
				"Eggs are not supposed to be green.");
Java GUI Dialog MessageBox


		JOptionPane.showMessageDialog(null,
			    "Eggs are not supposed to be green.",
			    "Inane warning",
			    JOptionPane.WARNING_MESSAGE);
Java GUI Dialog MessageBox


		JOptionPane.showMessageDialog(null,
			    "Eggs are not supposed to be green.",
			    "Inane error",
			    JOptionPane.ERROR_MESSAGE);
Java GUI Dialog MessageBox


		JOptionPane.showMessageDialog(null,
			    "Eggs are not supposed to be green.",
			    "A plain message",
			    JOptionPane.PLAIN_MESSAGE);
Java GUI Dialog MessageBox


		final ImageIcon icon = new ImageIcon(getClass().getResource("icon.gif"))
		JOptionPane.showMessageDialog(null,
			    "Eggs are not supposed to be green.",
			    "Inane custom dialog",
			    JOptionPane.INFORMATION_MESSAGE,
			    icon);
Java GUI Dialog MessageBox


		Object[] options = { "Yes, please", "No, thanks", "No eggs, no ham!" };
		int n = JOptionPane.showOptionDialog(null,
				"Would you like some green eggs to go " + "with that ham?",
				"A Silly Question", JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
		System.out.print(n); // Use n for response
Java GUI Dialog MessageBox


		int n = JOptionPane.showConfirmDialog(
			    null,
			    "Would you like green eggs and ham?",
			    "An Inane Question",
			    JOptionPane.YES_NO_OPTION);
		System.out.print(n); // Use n for response
Java GUI Dialog MessageBox


		Object[] options = {"Yes, please","No way!"};
		int n = JOptionPane.showOptionDialog(null,
			"Would you like green eggs and ham?",
			"A Silly Question",
			JOptionPane.YES_NO_OPTION,
			JOptionPane.QUESTION_MESSAGE,
			null,     //do not use a custom Icon
			options,  //the titles of buttons
			options[0]); //default button title
		System.out.print(n); // Use n for response
Java GUI Dialog MessageBox


		Object[] possibilities = {"ham", "spam", "yam"};
		String s = (String)JOptionPane.showInputDialog(
		                    null,
		                    "Complete the sentence:\n"
		                    + "\"Green eggs and...\"",
		                    "Customized Dialog",
		                    JOptionPane.PLAIN_MESSAGE,
		                    null,
		                    possibilities,
		                    "ham");

		//If a string was returned, say so.
		if ((s != null) && (s.length() > 0)) {
		    System.out.print("Green eggs and... " + s + "!");
		}
Java GUI Dialog MessageBox


		String s = (String)JOptionPane.showInputDialog(
		                    null,
		                    "Complete the sentence:\n"
		                    + "\"Input your name?\"",
		                    "Customized Dialog",
		                    JOptionPane.PLAIN_MESSAGE,
		                    null,
		                    null,
		                    "Name");

		//If a string was returned, say so.
		if ((s != null) && (s.length() > 0)) {
		    System.out.print("Hello... " + s + "!");
		}
Java GUI Dialog MessageBox






   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2013-08-22 08:53:02 / 2013-08-31 13:04:26
  Download : No files
 Sponsored Links / Related

 
รู้จักกับ Java กับ JFrame เครื่องมือหลักในการสร้าง GUI Window Form ด้วย JFrame
Rating :

 
การปรับแต่ง JFrame เช่น Title/Resizable/Maximum Window/Change Icon (Java)
Rating :

 
พื้นฐาน Java สร้าง Controls บน GUI และการสร้าง Action Event Handler กับ Controls
Rating :

 
พื้นฐานการสร้าง GUI Window Form ที่ประกอบด้วย 2 Form และการ Open Form (Java)
Rating :

 
พื้นฐาน Form และ GUI : JTextField , JLabel , JButton เพื่อรับข้อมูลและแสดงข้อมูล
Rating :

 
พื้นฐาน Java GUI : Dialog และ Popup สร้าง Input Dialog และ Custom Modal Dialog
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่