التعليم السعودي

الإنترفيس AdjustmentListener

الإنترفيس AdjustmentListener , الإنترفيس AdjustmentListener
الإنترفيس AdjustmentListener , الإنترفيس AdjustmentListener
الإنترفيس AdjustmentListener , الإنترفيس AdjustmentListener

الإنترفيس AdjustmentListener , الإنترفيس AdjustmentListener
الإنترفيس AdjustmentListener , الإنترفيس AdjustmentListener

المناهج السعودية
الإنترفيس AdjustmentListener يستخدم للتنبه كلما تم تحريك الـ JScrollBar.

مثال

Main.java

  1. import java.awt.event.AdjustmentEvent;
  2. import java.awt.event.AdjustmentListener;
  3. import javax.swing.JFrame;
  4. import javax.swing.JLabel;
  5. import javax.swing.JScrollBar;
  6. publicclass Main {
  7. publicstaticvoidmain(String[] args){
  8. JFrame frame = newJFrame(“AdjustmentListener demo”)// أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس
  9. JScrollBar scrollBar = newJScrollBar()// scrollBar إسمه Scroll Bar هنا أنشأنا
  10. JLabel label = newJLabel(“Adjustment Value: 50”)// label إسمه Label هنا أنشأنا
  11. label.setBounds(9090,15030)// frame في الـ label هنا قمنا بتحديد حجم و موقع الـ
  12. scrollBar.setBounds(403030150)// frame في الـ scrollBar هنا قمنا بتحديد حجم و موقع الـ
  13. scrollBar.setMinimum(1)// scrollBar هنا قمنا القيمة 1 كأصغر قيمة في الـ
  14. scrollBar.setMaximum(101)// scrollBar هنا قمنا القيمة 100 كأبر قيمة في الـ
  15. scrollBar.setValue(50)// الأولية scrollBar هنا قمنا بتحديد قيمة الـ
  16. scrollBar.setVisibleAmount(1)// تزداد أو تقل واحداً واحداً عند تحريكه scrollBar هنا جعلنا قيمة الـ
  17. frame.add(scrollBar)// frame في الـ scrollBar هنا أضفنا الـ
  18. frame.add(label)// frame في الـ label هنا أضفنا الـ
  19. frame.setSize(300250)// هنا قمنا بتحديد حجم النافذة. عرضها 300 و طولها 250
  20. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)// هنا جعلنا زر الخروج من النافذة يغلق البرنامج
  21. frame.setLayout(null)// لذلك قمنا بتحديد مكان كل شيء قمنا بإضافته في النافذة Layout Manager أي لم نستخدم أي null هنا وضعنا
  22. frame.setVisible(true)// هنا جعلنا النافذة مرئية
  23. // أي كلما تم تحريكه .scrollBar هنا نضع الأوامر التي نريد تنفيذها عند تغيير قيمة الـ
  24. scrollBar.addAdjustmentListener(newAdjustmentListener(){
  25. @Override
  26. publicvoidadjustmentValueChanged(AdjustmentEvent e){
  27. // سيتم عرض قيمته scrollBar في كل مرة يتم فيها تحريك الـ
  28. label.setText(“Adjustment Value: “ + scrollBar.getValue());
  29. }
  30. });
  31. }
  32. }

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

مثال يشرح طريقة تعريف الحدث AdjustmentListener في جافا

المصدر: الإنترفيس AdjustmentListener – المناهج السعودية

مقالات ذات صلة

اترك تعليقاً

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *

زر الذهاب إلى الأعلى