Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 12 - Designing Multiwindow Applications1 Chapter 12 Designing Multiwindow Applications 12.

Similar presentations


Presentation on theme: "Chapter 12 - Designing Multiwindow Applications1 Chapter 12 Designing Multiwindow Applications 12."— Presentation transcript:

1 Chapter 12 - Designing Multiwindow Applications1 Chapter 12 Designing Multiwindow Applications 12

2 Chapter 12 - Designing Multiwindow Applications2 Navigating Multiple Windows  You could design an application with separate stand-alone GUI classes for each task – AddCustomer, FindCustomer, AddBoat, etc.  Better approach is to link them through a main menu  Main menu displays buttons for each task

3 Chapter 12 - Designing Multiwindow Applications3 Designing the Main Menu  The frame instance is divided into rows using the GridLayout manager  Top row is used to display the marina’s logo  Bottom row contains a panel that uses the FlowLayout manager to place three buttons – one for each task

4 Chapter 12 - Designing Multiwindow Applications4 Designing the Main Menu 12

5 Chapter 12 - Designing Multiwindow Applications5 Designing the Main Menu  The main method is called when the class is loaded into memory  The actionPerformed method determines which button was clicked and invokes the appropriate method

6 Chapter 12 - Designing Multiwindow Applications6 Designing the Main Menu 12

7 Chapter 12 - Designing Multiwindow Applications7 Designing the Main Menu 12

8 Chapter 12 - Designing Multiwindow Applications8 Finding a Customer  Looks similar to the FindCustomer frame  Clicking the Close button causes the main menu to reappear  The Vector of customers is shared with the AddCustomers frame 12

9 Chapter 12 - Designing Multiwindow Applications9 Finding a Customer  The changes required include:  Delete the main method  When the MainMenu instantiates the FindCustomer class, it passes a reference to itself  The shutDown method in FindCustomer uses the reference to make the main menu visible  The getAll method of the Customer class is used to obtain the Vector of customers  See pp. 411 for code samples

10 Chapter 12 - Designing Multiwindow Applications10 Adding a Customer  The changes required include:  Delete the main method  When the MainMenu instantiates the AddCustomer class, it passes a reference to itself  The shutDown method in AddCustomer is the same as FindCustomer  See pp. 412 for code samples

11 Chapter 12 - Designing Multiwindow Applications11 Navigating a Problem Domain Relationship  The Customer and Boat classes have a one to one relationship  The assignBoatToCustomer method populates the reference attributes used in the Boat and Customer classes 12

12 Chapter 12 - Designing Multiwindow Applications12 Navigating a Problem Domain Relationship 12

13 Chapter 12 - Designing Multiwindow Applications13 Simulating a Customer and Boat Database  You can use a Vector class to simulate a database  You will learn more about database access in Java in Chapter 15  The Vector class is used to store Boat and Customer data  See samples codes in pp. 414

14 Chapter 12 - Designing Multiwindow Applications14 Adding a Customer  To add a new customer, click on the Add a Customer button on the main menu  The AddCustomer class needs the following modifications:  The caption for the Add a Customer button is changed to Add a Boat  The addCustomer method now has statements added to call AddBoat 12

15 Chapter 12 - Designing Multiwindow Applications15 Adding a Boat  After you enter the customer name, address, and phone number, you click addBoatButton, which invokes addCustomer to create a customer instance and display the AddBoat frame  You need to make the following changes:  The main method is deleted  When AddCustomer instantiates AddBoat, it passes a reference of itself and the newly created customer instance to the AddBoat constructor  The shutDown method in AddBoat is modified to make the AddCustomer frame visible 12

16 Chapter 12 - Designing Multiwindow Applications16 Adding a Boat

17 Chapter 12 - Designing Multiwindow Applications17 Finding a Customer and Boat  You can display a customer’s address and phone number plus their boat information together on the same frame  The frame is divided into four rows using the GridLayout manager  The first row is used for the marina logo 12

18 Chapter 12 - Designing Multiwindow Applications18 Finding a Customer and Boat

19 Chapter 12 - Designing Multiwindow Applications19 Finding a Customer and Boat  The second row contains a panel named centerPanel, which has one row and two columns  The left column contains a JList to display customer names  The right column contains a panel named centerRightPanel, which is divided into two columns  The first column holds a label to hold the customer’s name  The second column holds a label to hold the customer’s phone number

20 Chapter 12 - Designing Multiwindow Applications20 Finding a Customer and Boat  The third row contains a panel named lowerPanel that uses the FlowLayout manager to display a string containing the customer’s boat information  The code to display the logo and to create and display the list of customers is identical to the FindCustomer class 12

21 Chapter 12 - Designing Multiwindow Applications21 Finding a Customer and Boat  Two push buttons are created to the lower panel to Find and Close  The actionPerformed method is used to determine which button is clicked  The shutDown method makes the main menu visible and disposes the FindCustomerAndBoat frame

22 Chapter 12 - Designing Multiwindow Applications22 Finding a Customer and Boat  The findCustomer method is used to retrieve the customer name that was selected from the list  The Vector instance is called to retrieve the reference for the customer at the selected index  The getAddress and getPhoneNo methods are called to retrieve the appropriate information  The getBoat method is called to retrieve the boat information 12

23 Chapter 12 - Designing Multiwindow Applications23 Finding a Customer and Boat 12

24 Chapter 12 - Designing Multiwindow Applications24 Finding a Customer and Boat 12


Download ppt "Chapter 12 - Designing Multiwindow Applications1 Chapter 12 Designing Multiwindow Applications 12."

Similar presentations


Ads by Google