Programming Basics SQL HTML CSS JavaScript Python C++ Java JavaFX Swing Problem Solving English English Conversations Computer Fundamentals Learn Typing

Swingطريقة إنشاء JPasswordField

المثال التالي يعلمك طريقة إنشاء كائن من الكلاس JPasswordField و إضافته في النافذة.


مثال

Main.java
import javax.swing.JFrame;
import javax.swing.JPasswordField;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("JPasswordField demo"); // أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس
frame.setSize(300, 250); // هنا قمنا بتحديد حجم النافذة. عرضها 300 و طولها 250
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج
frame.setLayout(null); // في النافذة بنفسنا Password Field لذلك سنقوم بتحديد مكان الـ Layout Manager أي لم نستخدم أي null هنا وضعنا
JPasswordField passwordField = new JPasswordField(); // Password Field أي قمنا بإنشاء JPasswordField هنا أنشأنا كائن من الكلاس
passwordField.setBounds(40, 40, 200, 30); // frame في الـ Password Field هنا قمنا بتحديد حجم و موقع الـ
frame.add(passwordField); // frame في الـ Password Field هنا أضفنا الـ
frame.setVisible(true); // هنا جعلنا النافذة مرئية
}
}
import javax.swing.JFrame; import javax.swing.JPasswordField; public class Main { public static void main(String[] args) { JFrame frame = new JFrame("JPasswordField demo"); // أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس frame.setSize(300, 250); // هنا قمنا بتحديد حجم النافذة. عرضها 300 و طولها 250 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج frame.setLayout(null); // في النافذة بنفسنا Password Field لذلك سنقوم بتحديد مكان الـ Layout Manager أي لم نستخدم أي null هنا وضعنا JPasswordField passwordField = new JPasswordField(); // Password Field أي قمنا بإنشاء JPasswordField هنا أنشأنا كائن من الكلاس passwordField.setBounds(40, 40, 200, 30); // frame في الـ Password Field هنا قمنا بتحديد حجم و موقع الـ frame.add(passwordField); // frame في الـ Password Field هنا أضفنا الـ frame.setVisible(true); // هنا جعلنا النافذة مرئية } }

ستظهر لك النافذة التالية عند التشغيل.

قم بإدخال أي نص في الـ Password Field ثم لاحظ كيف سيتم إظهار نقاط بدلاً من الأحرف التي تدخلها.

طريقة إضافة JPasswordField في ال JFrame

الدورات

أدوات مساعدة

أقسام الموقع

دورات
مقالات كتب مشاريع أسئلة