Java data: Event-handling details in swing

Source: Internet
Author: User
Tags interface numeric key relative valid window

Listener : ActionListener

method : actionperformed

Event : ActionEvent

String Getactioncommand ()

A actioncommand is a string inside a control that identifies the state of the control.

This function can take the state of the control to determine exactly what to do.

int getmodifiers ()

Gets the key combination that the user presses simultaneously when this event occurs

Long Getwhen ()

Get "Timestamp When this event occurs"

Event causes: Click the button, select the content in the list box, return to the text box, and the timer expires

------------------------------------------------------------------

Listener : Adjustmentlistener

method : adjustmentvaluechanged

Event : adjustmentevent

Adjustable getadjustable ()

Adjustable is an interface in which various scroll bars implement this interface.

int Getadjustmenttype ()

Get the scrolling type, total Unit_increment,unit_decrement,block_increment,block_decrement,track total of 5 types

int GetValue ()

Gets the current value of the scroll slider

Event Cause: Scroll bar scrolling

------------------------------------------------------------------

Listener : ItemListener

method : itemstatechanged

Event : itemevent

Objedt GetItem ()

Gets the selected element. Note that the return value is object, and it should also be forced type conversion.

Itemselectable getitemselectable ()

Itemselectable is an interface that represents an object that contains n selectable child elements. This method returns the object that generated this event. The main purpose of this method is that if a list box is allowed to be multiple selections, the above method is not useful, you should use this method to get the list object, and then get the selected elements.

int Getstatechange ()

The state of getting the choice is selected or deselected

Event causes: Clicks of various buttons, selection of list boxes

-----------------------------------------------------------------

Listener : Focuslistener

methods : focusgained, Focuslost

Event : focusevent

Component getoppositecomponent ()

Gets the other object that participates in focus transformation. If the focus gets the event, returns the object that has the focus before it, or the object that gets the focus if the focus loses the event. Returns NULL if focus is shifted to another application

Boolean istemporary ()

The focus is on temporary transfers or permanent transfers. Temporary transfer: Drag the window with the mouse or the window becomes inactive. Other for permanent transfer.

Event causes: Focus changes for various components

------------------------------------------------------------------

Listener : KeyListener

methods : keypressed, keyreleased, keytyped

Event : keyevent

Char Getkeychar ()

This method is only valid in keytyped and returns the pressed character. Like pressing Shift+a and returning ' a '

int getKeyCode ()

Gets the integer encoding of the keys on the keyboard. Please note that the keys on the keyboard, such as the F1,ctrl,home key, and so on, are encoded accordingly. Key combinations are not supported, meaning that "shift+a" and "a" return the same content, all lowercase A's ASCII code. But the numeric key of the large keyboard and the keypad's numeric key return different contents.

static String getkeymodifierstext (int modifiers)

Converts a mask into a string, such as "Ctrl", "Ctrl+shift", and so on. Note that it is a static method

static String getkeytext (int keycode)

Returns the name of the button that keycode represents, such as "Home", "F1", and so on. Note that it's a statci method.

Event Reason: Tapping the keyboard on various components

----------------------------------------------------------------

Listener : MouseListener

methods : mouseclicked, mousepressed, mousereleased

Mouseentered, mouseexited

Event : MouseEvent

Point Getlocationonscreen ()

Returns the absolute coordinates of the mouse relative to the display screen (provided in Java version 1.6)

int Getxonscreen ()

Returns the absolute coordinates of the mouse relative to the X on the display screen (provided in Java version 1.6)

int Getyonscreen ()

Returns the absolute coordinates of the mouse relative to the y of the display screen (provided in Java version 1.6)

Point GetPoint ()

Returns the absolute coordinates of the mouse relative to the component

int GetX ()

Returns the absolute coordinates of the mouse's X relative to the component

int GetY ()

Returns the absolute coordinates of the mouse's Y relative to the component

void Translatepoint (int x, int y)

The mouse to do with a point plus an offset. For example, 2 parameters are 10, 20, you want to draw a line with the mouse, when you point to 100,100 start painting, the actual line is painted in 110,120

int GetClickCount ()

When this event occurs, how many mouse clicks (click, double-click, Triple hit ...). )

int Getbutton ()

When this event occurs, which key of the mouse is clicked: Nobutton, BUTTON1, BUTTON2 or BUTTON3

Boolean Ispopuptrigger ()

Whether it can trigger a pop-up menu. Because each platform triggers a pop-up menu, it should be detected in both mousepressed and mousereleased

Event Reason: Click the mouse on any component, move the cursor in or out

---------------------------------------------------------------------

Listener : Mousemotionlistener

methods : mousedragged, mousemoved

Event : MouseEvent

Ditto!

Event reason: Moving the mouse over any component

---------------------------------------------------------------------

Listener : Mousewheellistener

method : mousewheelmoved

Event : mousewheelevent

int Getscrolltype ()

Type of scrolling, whether to scroll Wheel_block_scroll by block or to scroll by unit Wheel_unit_scroll

int Getscrollamount ()

Returns the number of units that should be scrolled for the corresponding event. This method is valid if it is scrolled by unit.

int Getwheelrotation ()

The number of "click" Sound during scrolling of the mouse wheel. Roll up to a negative value and roll down to positive

Event Cause: Scroll the middle mouse button on any component

--------------------------------------------------------------------

Listener : WindowListener

methods : windowopened, Windowclosing, windowclosed, windowiconified

Windowdeiconified, windowactivated, windowdeactivated

Event : windowevent

Window GetWindow ()

Returns the Window object in which this event occurred

Window Getoppositewindow ()

If a focus shift occurs, return another window object that participates in this event, or null

int Getoldstate ()

The State before the window changes: NORMAL, iconified, Maximized_both

int Getnewstate ()

The State of the window after the change

Event Cause: Window changes

----------------------------------------------------------------------

Listener : Windowfocuslistener

methods : Windowgainedfocus, Windowlostfocus

Event : windowevent

Ditto!

Event Cause: Window Gets or loses focus

------------------------------------------------------------------------

Listener : Windowstatelistener

method : windowstatechanged

Event : windowevent

Ditto!

Event Cause: Window state Change

-------------------------------------------------------------------------



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.