You are on page 1of 50

Ta Trung Hieu – 20204970

Object-Oriented Programming
Lab 05: GUI Programming
Contents
1. Update UML...........................................................................................................................................1
2. Swing component....................................................................................................................................2
1. AWTAccumulator...............................................................................................................................2
2. SwingAccumulator..............................................................................................................................4
3. Organizing Swing components with Layout Managers......................................................................6
3. Create a graphical user interface for AIMS with Swing.......................................................................10
StoreScreen...............................................................................................................................................10
4. JavaFX API...........................................................................................................................................18
1. Create the FXML file........................................................................................................................18
2. Painter.fxml:......................................................................................................................................19
3. PainterController.java:.......................................................................................................................20
4. Painter.java:.......................................................................................................................................22
5. Setting up the View Cart Screen with ScreenBuilder...........................................................................23
1. Souce code sau khi kéo thả file cart.fxml:.........................................................................................24
6. Integrating JavaFX into Swing application – The JFXPanel class....................................................27
7. View the items in cart – JavaFX’s data-driven UI................................................................................28
8. Updating buttons based on selected item in TableView – ChangeListener..............................33
Code:.........................................................................................................................................................34
9. Deleting Media......................................................................................................................................34
10. Filter items in cart – FilteredList.............................................................................................34
11. Complete the Aims GUI application.................................................................................................35
Code UpdateStore:....................................................................................................................................36
12. Check previous code..........................................................................................................................38
1. Code AddBookToStore.....................................................................................................................38
2. Code AddCDToStore........................................................................................................................39
3. Code AddDVDToStore.....................................................................................................................40
4. Code AddItemToStore.......................................................................................................................41
13. Create a class which inherits from Exception..............................................................................43
1. Raise the PlayerException in the play() method.................................................................43
14. Update the Aims class......................................................................................................................45
15. Update Aims class diagram...............................................................................................................49

Page 1 of 50
Ta Trung Hieu – 20204970

1. Update UML

Page 2 of 50
Ta Trung Hieu – 20204970
2. Swing component
1. AWTAccumulator

Page 3 of 50
Ta Trung Hieu – 20204970
Kết quả: Nhập lần lượt 2 và 4 sẽ thu được kết quả tương ứng là 2 và 6

Page 4 of 50
Ta Trung Hieu – 20204970
2. SwingAccumulator

Kết quả: Nhập lần lượt 2 3 4 sẽ thu được tương ứng 2 5 9

Page 5 of 50
Ta Trung Hieu – 20204970

Page 6 of 50
Ta Trung Hieu – 20204970
3. Organizing Swing components with Layout Managers

Page 7 of 50
Ta Trung Hieu – 20204970

Page 8 of 50
Ta Trung Hieu – 20204970

Kết quả: đã nhập 789 và thu được kết quả tương ứng

Page 9 of 50
Ta Trung Hieu – 20204970
Sau khi ấn DEL

Sau khi ấn C:

Page 10 of 50
Ta Trung Hieu – 20204970
3. Create a graphical user interface for AIMS with Swing
StoreScreen

Page 11 of 50
Ta Trung Hieu – 20204970

Page 12 of 50
Ta Trung Hieu – 20204970

Page 13 of 50
Ta Trung Hieu – 20204970

Page 14 of 50
Ta Trung Hieu – 20204970

Page 15 of 50
Ta Trung Hieu – 20204970

Page 16 of 50
Ta Trung Hieu – 20204970

Page 17 of 50
Ta Trung Hieu – 20204970
Kết quả

Sau khi thêm thành công:

Menu

Page 18 of 50
Ta Trung Hieu – 20204970

4. JavaFX API
1. Create the FXML file
Create and open the FXML file in Scene Builder from Eclipse

Bị lỗi hiển thị gì đó nhưng em chưa tìm ra


Building the GUI
Kết quả màn hình Gui:

Page 19 of 50
Ta Trung Hieu – 20204970

2. Painter.fxml:

Page 20 of 50
Ta Trung Hieu – 20204970
3. PainterController.java:

Page 21 of 50
Ta Trung Hieu – 20204970

Page 22 of 50
Ta Trung Hieu – 20204970

4. Painter.java:

Page 23 of 50
Ta Trung Hieu – 20204970
5. Setting up the View Cart Screen with ScreenBuilder

Page 24 of 50
Ta Trung Hieu – 20204970
1. Souce code sau khi kéo thả file cart.fxml:

Page 25 of 50
Ta Trung Hieu – 20204970

Page 26 of 50
Ta Trung Hieu – 20204970

Kết quả sau khi design a View Cart Screen trên SceneBuilder như sau:

Page 27 of 50
Ta Trung Hieu – 20204970

6. Integrating JavaFX into Swing application – The JFXPanel class

Page 28 of 50
Ta Trung Hieu – 20204970
7. View the items in cart – JavaFX’s data-driven UI

Page 29 of 50
Ta Trung Hieu – 20204970
1. Code CartScreenController

Page 30 of 50
Ta Trung Hieu – 20204970

Page 31 of 50
Ta Trung Hieu – 20204970

Page 32 of 50
Ta Trung Hieu – 20204970

Page 33 of 50
Ta Trung Hieu – 20204970

8. Updating buttons based on selected item in TableView –


ChangeListener
“Play” Button: btnPlay
“Remove” Button: btnRemove

Page 34 of 50
Ta Trung Hieu – 20204970
Code:

9. Deleting Media

10. Filter items in cart – FilteredList


The TextField: tfFilter
The RadioButton “By ID”: radioBtnFilterId
The RadioButton “By Title”: radioBtnFilterTitle

Page 35 of 50
Ta Trung Hieu – 20204970

11. Complete the Aims GUI application

Page 36 of 50
Ta Trung Hieu – 20204970
Code UpdateStore:

Page 37 of 50
Ta Trung Hieu – 20204970

Page 38 of 50
Ta Trung Hieu – 20204970

12. Check previous code


1. Code AddBookToStore

Page 39 of 50
Ta Trung Hieu – 20204970
2. Code AddCDToStore

Page 40 of 50
Ta Trung Hieu – 20204970
3. Code AddDVDToStore

Page 41 of 50
Ta Trung Hieu – 20204970
4. Code AddItemToStore

Page 42 of 50
Ta Trung Hieu – 20204970

Page 43 of 50
Ta Trung Hieu – 20204970

13. Create a class which inherits from Exception

1. Raise the PlayerException in the play() method


- Update play() method in DigitalVideoDisc

Page 44 of 50
Ta Trung Hieu – 20204970

Update play() in Track

Update play() in the Playable interface

Update play() in CompactDisc

Page 45 of 50
Ta Trung Hieu – 20204970

14. Update the Aims class

Page 46 of 50
Ta Trung Hieu – 20204970

Page 47 of 50
Ta Trung Hieu – 20204970

Page 48 of 50
Ta Trung Hieu – 20204970

Page 49 of 50
Ta Trung Hieu – 20204970
15. Update Aims class diagram

Page 50 of 50

You might also like