چند سوال در مورد Mouse event ها در جاوا .

سلام ،چندتا سوال در مورد mouse listener داشتم ممنون میشم اگر کسی پاسخ بده.

1)چرا جاوا بین یک MouseListener, MouseMotionLisetner و یک MouseWheelListener تمایز قائل میشه؟

 

2)اینترفیس MouseInputListener خالی است پس اصلن چرا وجود داره؟چه فایده ای داره؟

 

3) دو کلاس MouseAdapter وMouseMotionAdapter چه اهمیت ویژه ای دارن؟

پاسخ ها

sokanacademy forum
کاربر سکان آکادمی 8 سال پیش

سلام در جواب سوال اولتون...

به کتاب جاوا دایتل برید....

فصل 12صفحه ی 678 موس ایونت ها....

خوب میان انواع حرکت موس را دسته بندی می کنند بعد سه تا متد کلاس برای اون تعریف کردند.

حرکت موس که فقط شامل کلیک است

حرکت دوم شامل درگ کردن و کشیدن است

حرکت سوم چرخ واری....

خوب اقای طراح زبان ترجیج داده سه دسته کند...

MouseListener Interface is used for receiving mouse events like mouse key press, mouse key release, mouse click, mouse enter and mouse exit on a component like Frame etc.

MouseMotionListener Interfaces is used for receiving mouse motion events like mouse drag, mouse move etc.

MouseWheel Listener Interface is used for receiving Mouse Wheel event, that is mouse wheel moved.

 بعد تعریف دقیق متد هاهم بد نیست داخل دایتل نگاهی بیندازید...

Methods of interface MouseListener
public void mousePressed( MouseEvent event )
Called when a mouse button is pressed with the mouse cursor on a component.
public void mouseClicked( MouseEvent event )
Called when a mouse button is pressed and released on a component without moving the
mouse cursor.
public void mouseReleased( MouseEvent event )
Called when a mouse button is released after being pressed. This event is always preceded
by a mousePressed event.
public void mouseEntered( MouseEvent event )
Called when the mouse cursor enters the bounds of a component.
public void mouseExited( MouseEvent event )
Called when the mouse cursor leaves the bounds of a component.
Methods of interface MouseMotionListener
public void mouseDragged( MouseEvent event )
Called when the mouse button is pressed with the mouse cursor on a component and the
mouse is moved. This event is always preceded by a call to mousePressed.
public void mouseMoved( MouseEvent event )
Called when the mouse is moved with the mouse cursor on a component.

 

sokanacademy forum
کاربر سکان آکادمی 8 سال پیش

در جواب سوال دومتون MouseInputListener یک اینترفیس است که از هردو MouseListener, MouseMotionLisetner ارث بری کرده و هر دو دسته را شامل می شود...

MouseInputListener
    This is just a convenience interface to combine all the methods of MouseListener and MouseMotionListener. The only tricky thing about it is its package: javax.swing.event rather than MouseInputListener
    This is just a convenience interface to combine all the methods of MouseListener and MouseMotionListener. The only tricky thing about it is its package: javax.swing.event rather than 

 

که این اینترفیس برای موس است،یعنی چی اینترفیس خالی داره؟متوجه منظورتون دقیق نشدم ...

نوشته برای راحتی

دوم داخل هر زبانی یک سری کار را از چند روش می شه انجام داد یعنی کلاس و متدهای متفاوتی براش ممکنه تعریف کنند این که هر کدام کاربر راحت بود استفاده کنه و در اصل موضوع شاید تفاوت خیلی فاحش با هم نداشته باشند،این به سلیقه طراح زبان برمی گرده

مثلا زمانی که جاوامال سان بودن نمودار درختی کلاس ها ومتدها زیرشاخته یک عبارتی بودن که داخلش کلمه سان بود،ولی بعد که اوراکل

اومد کلی تغییر داخلش ایجاد کرد...اینها دیگه سوال کردن نداره

مثلا داخل سی شارپ یک متد پرینت کردنش داخل کنسول اینه

 

Console.WriteLine("A");

که از نظر من مهندسی نرم افزارش خیلی ضعیفه چون متدهاش به سختی به ذهن سپرده می شود..ولی زبان سی پلاس پلاس و جاوا دقیقا برعکس هستند متدهاش سریعتر کاربر حفظ خواهد شد.

کلا سعی کن با کلاس ها ومتدها دوست باشی و از اون ها استفاده کنی همین

online-support-icon