Top Banner
Dr. Rania Khairy Software Development and Professional Practice JavaFX UI Controls and Multimedia 1
39

JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Apr 16, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

JavaFX UI Controls and

Multimedia

1

Page 2: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Motivations • A graphical user interface (GUI) makes a system user-friendly and easy to use.

• Creating a GUI requires creativity and knowledge of how GUI components work.

• Previous lecture briefly introduced several GUI components. This lecture introduces the frequently used GUI components in detail.

2

Page 3: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Frequently Used UI Controls

3

Page 4: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Labeled A label is a display area for a short text, a node, or both. It is often used to label other controls (usually text fields). Labels and buttons share many common properties. These common properties are defined in the Labeled class.

4

Page 5: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Label The Label class defines labels.

5

Page 6: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

6

LabelWithGraphics.java

Page 7: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

7

LabelWithGraphics.java

Page 8: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

ButtonBase and Button A button is a control that triggers an action event when clicked. JavaFX provides regular buttons, toggle buttons, check box buttons, and radio buttons. The common features of these buttons are defined in ButtonBase and Labeled classes.

8

Page 9: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

9

ButtonDemo.java

Page 10: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

10

ButtonDemo.java

Page 11: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

CheckBox A CheckBox is used for the user to make a selection. Like Button, CheckBox inherits all the properties such as onAction, text, graphic, alignment, graphicTextGap, textFill, contentDisplay from ButtonBase and Labeled.

11

Page 12: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

12

CheckBoxDemo.java

Page 13: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

13

CheckBoxDemo.java

Page 14: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

RadioButton Radio buttons, also known as option buttons, enable you to choose a single item from a group of choices.

14

Page 15: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

15

RadioButtonDemo.java

Page 16: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

16

RadioButtonDemo.java

Page 17: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

TextField A text field can be used to enter or display a string. TextField is a subclass of TextInputControl

17

Page 18: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

18

TextFieldDemo.java

Page 19: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

19

TextFieldDemo.java

Page 20: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

TextArea A TextArea enables the user to enter multiple lines of text.

20

Page 21: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

TextArea Example

21

Page 22: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

22

Page 23: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

23

Page 24: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

ComboBox

A combo box, also known as a choice list or drop-down list, contains a list of items from which the user can choose.

24

Page 25: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

ComboBox Example

25

This example lets users view an image and a description of a country's flag by selecting the country from a combo box.

Page 26: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

ListView

A list view is a component that performs basically the same function as a combo box, but it enables the user to choose a single value or multiple values.

26

Page 27: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Example: Using ListView

This example gives a program that lets users select countries in a list and display the flags of the selected countries in the labels.

27

Page 28: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

ScrollBar A scroll bar is a control that enables the user to select from a range of values. The scrollbar appears in two styles: horizontal and vertical.

28

Page 29: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Scroll Bar Properties

29

Page 30: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Example: Using Scrollbars

This example uses horizontal and vertical scrollbars to control a message displayed on a panel. The horizontal scrollbar is used to move the message to the left or the right, and the vertical scrollbar to move it up and down.

30

Page 31: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Slider Slider is similar to ScrollBar, but Slider has more properties and can appear in many forms.

31

Page 32: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Example: Using Sliders

Rewrite the preceding program using the sliders to control a message displayed on a panel instead of using scroll bars.

32

Page 33: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Case Study: Bounce Ball

Aprogram that displays a bouncing ball. You can add a slider to control the speed of the ball movement.

33

Page 34: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Case Study: TicTacToe

34

Cell

-token: char

+getToken(): char

+setToken(token: char): void

-handleMouseClick(): void

javafx.scene.layout.Pane

-char token

+getToken

+setToken

+paintComponet

+mouseClicked

Token used in the cell (default: ' ').

Returns the token in the cell.

Sets a new token in the cell.

Handles a mouse click event.

Page 35: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Case Study: TicTacToe, cont.

35

Page 36: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Media You can use the Media class to obtain the source of the media, the MediaPlayer class to

play and control the media, and the MediaView class to display the video.

36

Page 37: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

MediaPlayer

The MediaPlayer class playes and controls the media with properties such as

autoPlay, currentCount, cycleCount, mute, volume, and totalDuration.

37

Page 38: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

MediaView

The MediaView class is a subclass of Node that provides a view of the

Media being played by a MediaPlayer. The MediaView class provides the

properties for viewing the media.

38

Page 39: JavaFX UI Controls and Multimedia - LearngroupJavaFX UI Controls and Multimedia 1 . Dr. Rania Khairy Software Development and Professional Practice Motivations • A graphical user

Dr. Rania Khairy Software Development and Professional Practice

Case Study: National Flags and Anthems

This case study presents a program that displays a nation’s flag and plays its anthem.

39