user interface examples - mycourseville-default.s3.ap

17
More User Interface Examples

Upload: others

Post on 25-Dec-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

More User Interface Examples

Trying Key press and Mouse click[KeyPress.java]

Interest Points:Text Wrap and Scroll Pane

Scroll Pane

KeyPress in TextArea

Pressed Key and “Ora!” keep on growing as we keep pressing!

What if we want the event to fire just 1 time!? (see

later)

Mouse Drag in TextArea!

Nothing happens!

But it works when you are dragging the left most side

of the area!

Make sure you understand the actual

meaning of events inside a component!

Mouse Click in TextArea

It detects ONCE, when the mouse

is RELEASED.

Button click

It detects ONCE, when the button

is RELEASED.

KeyPress inTextArea, how to fire the action only once?

Use booleancondition to check?

Set the boolean on key press and reset it on key release

[KeyTrigger.java]

But it’s a compile error!!

Cannot use local variable!

Solution 1: use a class variable instead

[KeyTrigger01.java]

Only 1 Ora! while we keep pressing key “d”.

But “d” is still increasing since the text area is

editable.

Solution 2: use a listener that remember the trigger status

[KeyTrigger02.java]

Yes. You can write your own

handler (implements

from an existing one).

Interesting feature: Drag and Drop

[HelloDragAndDrop.java] –from oracle tutorial

What you need to do.

Source Destination

setOnDragDetected• Call method

startDragAndDrop and indicate its transfer mode (COPY,MOVE,orLINK)

• Copy data to transfer onto dragboard(clipboard for drag-and-drop)

setOnDragOver• Call method

acceptTransferModesindicating its transfer mode (COPY,MOVE,orLINK). The transfer mode must match the source.

setOnDragEntered

setOnDragExited

setOnDragDropped• Call method

setDropCompleted

Visual feedback

setOnDragDone• Clear original data if

necessary.

Source: setOnDragDetected to initialize.

Copy content as a ClipBoardContent

and put it in our drag board.

Consume event so that it does not get passed on to other

related nodes.

Destination: setOnDragOverto set a matching transfer mode.

Destination:setOnDragEnteredand setOnDragExitedto provide Visual Feedback

Source must not

come from itself. Must verify

that data has a correct

type.

Destination: setOnDragDropped

This is what happens when the mouse is released on the destination (DRAG_OVER must work and transfer mode must also be compatible).

Must be called, or the drag is never

success.

Source: setOnDragDone

If this is null, then the

drag fails.