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