التعليم السعودي
طريقة إنشاء JPasswordField
طريقة إنشاء JPasswordField
طريقة إنشاء JPasswordField
طريقة إنشاء JPasswordField
طريقة إنشاء JPasswordField
طريقة إنشاء JPasswordField
طريقة إنشاء JPasswordField
مثال
- import javax.swing.JFrame;
- import javax.swing.JPasswordField;
- publicclass Main {
- publicstaticvoidmain(String[] args){
- JFrame frame = newJFrame(“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 = newJPasswordField(); // Password Field أي قمنا بإنشاء JPasswordField هنا أنشأنا كائن من الكلاس
- passwordField.setBounds(40, 40, 200, 30); // frame في الـ Password Field هنا قمنا بتحديد حجم و موقع الـ
- frame.add(passwordField); // frame في الـ Password Field هنا أضفنا الـ
- frame.setVisible(true); // هنا جعلنا النافذة مرئية
- }
- }
•ستظهر لك النافذة التالية عند التشغيل.
•قم بإدخال أي نص في الـ Password Field ثم لاحظ كيف سيتم إظهار نقاط بدلاً من الأحرف التي تدخلها.
المصدر: طريقة إنشاء JPasswordField – المناهج السعودية