Swingطريقة تبديل النقاط التي تظهر بداخل الـ JPasswordField بأحرف أو رموز أو أرقام أخرى
المثال التالي يعلمك طريقة تبديل النقاط التي تظهر بداخل كائن الـ JPasswordField بأحرف, رموز أو أرقام أخرى.
مثال
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 هنا قمنا بتحديد حجم و موقع الـ
passwordField.setEchoChar('?'); // 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 هنا قمنا بتحديد حجم و موقع الـ
passwordField.setEchoChar('?'); // frame في الـ Password Field هنا قمنا بتغير الحرف الذي سيظهر بداخل الـ
frame.add(passwordField); // frame في الـ Password Field هنا أضفنا الـ
frame.setVisible(true); // هنا جعلنا النافذة مرئية
}
}
ستظهر لك النافذة التالية عند التشغيل.
قم بإدخال أي نص في الـ Password Field ثم لاحظ كيف سيتم وضع علامات إستفهام بدلاً من الأحرف التي تدخلها.