Non-professional Code Nong Java Learning Notes user graphical interface design and implementation-listener events for all controls

Source: Internet
Author: User

User graphical interface design and implementation-monitoring events

System.applet.Applet

(a) User-defined components

1. Drawing graphics

Public voit piant (ghraphics g) {G.drawline and other graphic names (coordinate 1234); G.file drawing name (coordinates 123)}

2. Set the Font-font class

(1) Define Font:font myfont=new font ("Font", "style", font size);

For example: Font myfont=new font ("Song Body", font.bold,12);

(2) reference to the defined font: class/container/control, etc. setFont (myfont);

For example: Graphics g=new graphics (); G.setfont (MyFont);

3. Set color: Color Co=new color (r,g,b), primary color, type int or float; object: SetColor (CO);

In addition, there are:

. Setbackcolor (color co); GetBackColor (color co); Setforecolor (color co); GetForeColor (color co);

4. Display Picture: Binary image (unlike pictures, generally less, most calls to some system intrinsic image)

Graphics g=new grahphics (); G.drawimage (Brush type Object, X0,y0,x1,y1, Object (drawing paper));

5. Animating: The same principle as Flash animation, picture motion

(ii) Java's standard components and event handling

1.java Event handling mechanism:

Event Source + Register Listener Object--trigger event actionevent-call and pass parameter--listener implements interface;

2.GUI Standard Components Overview

The general process of using control components:

(1) Creating a new object for the component class, specifying the property (appearance size)--Object instantiation

(2) Add to the relevant location or container

(3) Register to an event listener to make it easier to respond to events that occur on the control

3. Event monitoring and interface

(1) ActionEvent action Event

Cause: Click to double-tap to select Menu Text carriage return etc.

Registration Method: Event source object. addActionListener (Listener)

Monitoring interface: ActionListener

Treatment method: actionperformed (ActionEvent e)

(2) ItemEvent Project Events

Reason: List box change, dropdown menu selection, check change status, etc.

Registration method: Event source. Additemlistener (Listener)

Monitoring interface: ItemListener

Treatment method: itemstatechanged (ItemEvent e)

(3) MouseEvent mouse events

Cause: Mouse Click to enter and so on changes

Registration method: Event source. Addmouselistener (Listener)

Monitoring interface: MouseListener

Treatment method: mouseclick/mouseenter/mouseexit/mousepressed/mousereleased (MouseEvent e)

(4) Mousemotion Mouse movement Event (mouse movement)

Cause: Mouse Move drag

Registration method: Event source. Mousemotionlistener (Listener)

Monitoring interface: Mousemotionevent

Treatment method: mousemove/mousedragged (MouseEvent e)

(5) KeyEvent keyboard operation event

Cause: Keyboard operation

Registration method: Event source. Addkeylistener (Listener)

Monitoring interface: KeyListener

Treatment method: keypress/keyrelease/keytyped (KeyEvent e)

(6) FocusEvent Focus Event

Cause: Component focus acquisition and loss

Registration method: Event source. Addfocuslistener (Listener)

Monitoring interface: Focuslistener

Treatment method: Focusgained/focuslost (FocusEvent e)

(7) AdjustmentEvent adjustment events

Cause: Scroll bar change

Registration method: Event source. Addadjustmentlistener (Listener)

Monitoring interface: Adjustmentlistener

Treatment method: adjustmentvaluechanged (AdjustmentEvent e)

(8) TextEvent text Event

Cause: Text content changes

Registration method: Event source. Addtextchangedlistener (Listener)

Monitoring interface: TextListener

Treatment method: textvaluechanged (TextEvent e)

(9) ComponentEvent component Events

Cause: Build move, change size, visibility, etc.

Registration method: Event source. Addcomponentlistener (Listener)

Monitoring interface: Componentlistener

Treatment method: Componenthidden/moved/resized/shown (ComponentEvent e)

() windowevent window events

Cause: Form changes

Registration method: Event source. Addwindowslistener (Listener)

Monitoring interface: WindowListener

Treatment method: Windowclosed/opened/closing/activated/deactivated/iconfied (minimized)/

Windowdeiconfied (maximized) (WindowEvent e)

(one) ContainerEvent container events

Cause: container increase or removal

Registration method: Event source. Addcontainerlistener (monitor)

Monitoring interface: ContainerListener

Treatment method: componentadd/removed (comtainerevent e)

Non-professional Code Nong Java Learning Notes user graphical interface design and implementation-listener events for all controls

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.