الجامعات العربية

الإنترفيس 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.  
  7. publicclass Main {
  8.  
  9. publicstaticvoidmain(String[] args){
  10.  
  11. JFrame frame = newJFrame(“AdjustmentListener demo”); // أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس
  12. JScrollBar scrollBar = newJScrollBar(); // scrollBar إسمه Scroll Bar هنا أنشأنا
  13. JLabel label = newJLabel(“Adjustment Value: 50”); // label إسمه Label هنا أنشأنا
  14.  
  15. label.setBounds(90, 90,150, 30); // frame في الـ label هنا قمنا بتحديد حجم و موقع الـ
  16. scrollBar.setBounds(40, 30, 30, 150); // frame في الـ scrollBar هنا قمنا بتحديد حجم و موقع الـ
  17.  
  18. scrollBar.setMinimum(1); // scrollBar هنا قمنا القيمة 1 كأصغر قيمة في الـ
  19. scrollBar.setMaximum(101); // scrollBar هنا قمنا القيمة 100 كأبر قيمة في الـ
  20. scrollBar.setValue(50); // الأولية scrollBar هنا قمنا بتحديد قيمة الـ
  21. scrollBar.setVisibleAmount(1); // تزداد أو تقل واحداً واحداً عند تحريكه scrollBar هنا جعلنا قيمة الـ
  22.  
  23. frame.add(scrollBar); // frame في الـ scrollBar هنا أضفنا الـ
  24. frame.add(label); // frame في الـ label هنا أضفنا الـ
  25.  
  26. frame.setSize(300, 250); // هنا قمنا بتحديد حجم النافذة. عرضها 300 و طولها 250
  27. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج
  28. frame.setLayout(null); // لذلك قمنا بتحديد مكان كل شيء قمنا بإضافته في النافذة Layout Manager أي لم نستخدم أي null هنا وضعنا
  29. frame.setVisible(true); // هنا جعلنا النافذة مرئية
  30.  
  31. // أي كلما تم تحريكه .scrollBar هنا نضع الأوامر التي نريد تنفيذها عند تغيير قيمة الـ
  32. scrollBar.addAdjustmentListener(newAdjustmentListener(){
  33. @Override
  34. publicvoidadjustmentValueChanged(AdjustmentEvent e){
  35. // سيتم عرض قيمته scrollBar في كل مرة يتم فيها تحريك الـ
  36. label.setText(“Adjustment Value: “ + scrollBar.getValue());
  37. }
  38. });
  39.  
  40. }
  41.  
  42. }

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

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

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

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

اترك رد

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

أنت تستخدم إضافة Adblock

برجاء دعمنا عن طريق تعطيل إضافة Adblock