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

Swingطريقة إظهار الحروف التي يتم إدخالها في الـ JPasswordField

المثال التالي يعلمك طريقة إظهار الحروف التي يتم إدخالها في الـ Password Field.


مثال

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 هنا قمنا بتحديد حجم و موقع الـ
passwordField.setEchoChar('\0'); // 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('\0'); // frame في الـ Password Field هنا قمنا بإظهار أي أحرف يتم إدخالها في الـ frame.add(passwordField); // frame في الـ Password Field هنا أضفنا الـ frame.setVisible(true); // هنا جعلنا النافذة مرئية } }

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

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

إظهار النص المدخل في ال JPasswordField في جافا