חזרה
ש- כל הבאגים ב-Scrollbar תוקנו ב-JDK 1.1.3 נכון או לא נכון? אם לא נכון הסבירו מדוע.
ת- לא נכון. ב-JDK 1.1.3 נראה שיש לפחות שני באגים ב-Scollbar . באג אחד גורם לאירוע track (שקשור לגרירת הבועה
באובייקט ה-scrollbar ) להחזיר ערכים חיוביים גדולים כמו 65535 כאשר היה צריך להחזיר ערכים שליליים קטנים כמו 1-.
הבאג השני נותן לגרסאות שונות של האירוע להחזיר ערך גדול ממה שהיה מחושב על יד שימוש בערכי המינימום
והמקסימום ביחד עם רוחב הבועה.
ש - הבאגים המתוארים לעיל גורמים למרכיב ה-Scrollbar להיות לגמרי לא שמיש. נכון או לא נכון? אם לא נכון הסבירו
מדוע.
ת- לא נכון. למרות ששני הבאגים יוצרים אי נוחות משמעותית, ניתן "לעקוף" אותם על ידי שינויים מספריים.
ש - כדי ליצור אובייקט listner עבור Scrollbar צריך לממש את מנשק ScrollbarListner או להרחיב את המחלקה
ScrollbarAdapter. נכון או לא נכון? אם לא נכון הסבירו מדוע.
ת- לא נכון. כדי ליצור אובייקט listner עבור Scrollbar לא מממשים את מנשק ScrollbarListner או מרחיבים את
המחלקה ScrollbarAdapter, משום שהם אינם קיימים. במקום זה יש לממש את מנשק AdjustmentListner .
ש - כדי ליצור אובייקט listner עבור Scrollbar צריך לממש את מנשק AdjustmentListnerאו להרחיב את המחלקה
AdustmentAdapter. נכון או לא נכון? אם לא נכון הסבירו מדוע.
ת- לא נכון. לא קיימת מחלקה AdustmentAdapter , היא אינה נצרכת משום שמנשק AdjustmentListnerמצהיר רק
על מתודה אחת:
public abstract void adjustmentValueChanged(AdjustmentEvent e) |
ש - המתודה adjustmentValueChanged() נקראת כאשר ערך אובייקט ה-Scrollbar משתנה. נכון או לא נכון? אם לא
נכון הסבירו מדוע.
ת- נכון.
ש - ישנם חמישה סוגים של אירועי התאמה שמתאימים ל-5 הדרכים להזזת הבועה ב- scroolbar . נכון או לא נכון? אם לא
נכון הסבירו מדוע.
ת- נכון.
ש - כמו ברוב המחלקות האחרות ב- AWT, מנשק AdjustmentListener מצהיר על מתודה נפרדת לכל סוג של אירוע.
כל אחד ממתודות אלו חייבת להיות ממומשת בכל מחלקה שמממשת את מנשק AdjustmentListener .
נכון או לא נכון? אם לא נכון הסבירו מדוע.
ת - לא נכון. רק מתודה אחת מוצהרת במנשק AdjustmentListener , שם המתודה: adjustmentValueChanged() .
ש - המתודה adjustmentValueChanged() מקבלת כפרמטר אובייקט מסוג AdjustmentEvent וסוג האירוע מוצפן
לתוך האובייקט. נכון או לא נכון? אם לא נכון הסבירו מדוע.
ת - נכון.
ש - בנוסף לסוג האירוע , מידע נוסף מוצפן לתוך האובייקט ומועבר למתודה adjustmentValueChanged(). תנו דוגמאות
לשני סוגי מידע שמוצפנים לתוך האובייקט.
ת - מידע כמו ערך ה-Scrollbar ושם ה-Scrollbar מוצפן גם הוא לתוך האובייקט.
ש- סוגי אירועי ההתאמה (adjustment) מוגדרים כמשתנים סטטיים במחלקה AdjustmentEvent . מהם שמות
המשתנים ? וכיצד הם מתאימים לדרכים להזזת הבועה באובייקט Scrollbar ?
ת - שמות המשתנים ויחסם לדרכים להזזת הבועה באובייקט Scrollbar:
Scrollbar - לחיצה על הכפתור בקצה אחד של ה-UNIT_INCREMENT
Scrollbar - לחיצה על הכפתור בקצה השני של ה-UNIT_DECREMENT
- לחיצה על הרווח שבין הבועה לבין כפתור אחד BLOCK_INCREMENT
- לחיצה על הרווח שבין הבועה לבין הכפתור השני BLOCK_DECREMENT
TRACK - גרירת הבועה
ש - לפחות שני מושגים אחרים מתייחסים לרוחב הבועה, בתיעוד על ה-Scrollbar מהם?
ת - המושגים האחרים המתארים את רוחב הבועה הם: page size (גודל עמוד) ו- visible (עמוד נראה). נראה שמושגים
אלה קשורים לשימוש ב-Scrollbar בצד או בתחתית חלון טקסט כשגודל הבועה מראה על כמות הטקסט הנראה בחלון
ביחס לכמות הטקסט בכל המסמך.
ש - ב-JDK 1.1.3 ערך אובייקט ה-Scrollbar מייצג את מרכז הבועה. נכון או לא נכון? אם לא נכון הסבירו מדוע.
ת - לא נכון. ערך אובייקט ה-Scrollbar מייצג קצה של הבועה . לדוגמא ב-Scrollbar אופקי הערך מייצג את הקצה
השמאלי של הבועה. אם רוצים את אמצע הבועה יש לבצע שינויים נומריים (שקשורים למחצית רוחב הבועה) בערך
שממש מוחזר על ידי האירוע.
ש - כל הפרמטרים הנדרשים לאתחול אובייקט Scrollbar מועברים כפרמטרים לאחת מפונקציות ה-constructor .
נכון או לא נכון? אם לא נכון הסבירו מדוע.
ת - לא נכון. למרות שחמישה פרמטרים שונים מועברים ל-constructor כדי לאתחל אובייקט Scrollbar, פרמטרים חשובים
אחרים כמו BlockIncrement ו- UnitIncrement אינם כלולים ברשימת הפרמטרים. הם חייבים להיקבע על ידי
מתודות כגון setBlockIncrement().
ש - המחלקה AdjusmentEvent מכילה 4 מתודות המשמשות להשיג מידע על האירוע. מהן ואיזה מידע הן מחזירות?
ת - 4 המתודות והמידע שהן מחזירות:
* מתודת getAdjustable() מחזירה מידע המכיל את זיהוי האובייקט שיצר את האירוע.
* מתודתgetAdjustmentType() מחזירה מידע המכיל את זיהוי סוג האירוע (לחיצה על כפתור ה-Scrollbar,
גרירת העכבר וכו').
* מתודת paramString() מכילה מידע שחופף במידה מסוימת עם שתי המתודות הקודמות.
* מתודת getValue() מחזירה את הערך המיוצר על ידי ה- adjustment.
ש - כתבו תכנית שתבצע את המפרט הכתוב בהערות של התכנית להלן.
ת - ראו התכנית להלן:
/*File SampProg125.java from lesson 90 Copyright 1997, R. G. Baldwin Without viewing the following solution, write a Java application that meets the specifications given below. To accommodate this program, you will need to be using JDK 1.1.3 or a later version. Write an application that places a vertical Scrollbar and a Label on a Frame. The Label is used to display the position of the center of the bubble in the Scrollbar. The Scrollbar values should range from approximately -50 to +50 (exact end points are difficult to achieve). The width of the bubble should be 10 units. When you click on the buttons at the end of the Scrollbar, the bubble should move by 3 units. When you click in the area between the bubble and the buttons, the bubble should move by 6 units. When the program starts, the bubble should be centered and the Label should indicate a bubble position of 0. Closing the frame terminates the program. End of specifications. */ //========================================================= import java.awt.*; import java.awt.event.*; class SampProg125{ public static void main(String[] args){ GUI gui = new GUI(); }//end main }//end class SampProg125 //========================================================== class GUI{ Scrollbar myScrollbar; Label displayWindow; int bubbleWidth;//needs to be accessible by event handler GUI(){ Frame myFrame = new Frame("Copyright 1997, R.G.Baldwin"); bubbleWidth = 10; int initialPosition = 0 - bubbleWidth/2; int min = -50 - bubbleWidth/2; int max = 50 + bubbleWidth/2; myScrollbar = new Scrollbar(Scrollbar.VERTICAL, initialPosition, bubbleWidth, min, max); myScrollbar.setBlockIncrement(6); myScrollbar.setUnitIncrement(3); displayWindow = new Label("value = 0"); //add components to the GUI myFrame.add("East", myScrollbar); myFrame.add("North", displayWindow); myFrame.setSize(300,300); myFrame.setVisible(true); //Instantiate a listener object for the Scrollbar and // register it to receive notification of adjustment // events. MyScrollbarListener myScrollbarListener = new MyScrollbarListener(this); //Note that the Scrollbar listener is not added as a // ScrollbarListener but rather is added as an // AdjustmentListener. myScrollbar.addAdjustmentListener(myScrollbarListener); //Close Frame to terminate. myFrame.addWindowListener(new MyWindowListener()); }//end constructor }//end class GUI //================================================================= //Note that unlike some other components which have their // own listener interface, this class does not implement // ScrollbarListener because there is no such interface. // Rather, the AdjustmentListener interface is used as a // listener interface for Scrollbars. class MyScrollbarListener implements AdjustmentListener{ GUI thisObject; //save ref to GUI object here MyScrollbarListener(GUI objectIn){//constructor thisObject = objectIn; }//end constructor public void adjustmentValueChanged(AdjustmentEvent e){ int value; //Display the value of the Scrollbar object in the // Label. The value should represent the position // of the bubble. value = e.getValue();//get and save the value //The following code is here to work around a possible // bug in the Scrollbar object where small negative // values are reported as very large positive values // when the Scrollbar is adjusted by sliding the bubble. if(value > 65000) value = value - 65536; thisObject.displayWindow.setText("Value = " + (value + thisObject.bubbleWidth/2)); //The following seems like a kludge but is required to // make the scrollbar bubble stay put. Otherwise, it // jumps back to the previous value when you try to // move it. thisObject.myScrollbar.setValue(value); }//end adjustmentValueChanged() }//end class MyScrollbarListener //========================================================= //Listener to terminate the program when the Frame is // closed. class MyWindowListener extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); }//end windowClosing() }//end class MyWindowListener |