Presentation is loading. Please wait.

Presentation is loading. Please wait.

IM103 week 11 Part 2 P532 Case Study part 2: the Airport GUI Learning objectives By the end of this lecture you should be able to:  use the JTabbedPane.

Similar presentations


Presentation on theme: "IM103 week 11 Part 2 P532 Case Study part 2: the Airport GUI Learning objectives By the end of this lecture you should be able to:  use the JTabbedPane."— Presentation transcript:

1 IM103 week 11 Part 2 P532 Case Study part 2: the Airport GUI Learning objectives By the end of this lecture you should be able to:  use the JTabbedPane Swing class to create an attractive user interface;  add tool tips to Swing components using the setToolTipText method;  add short cut keys to Swing menu items using the setMnemonic method.

2 Swing based design of the GUI JFrame JTabbedPane JMenuBar JPanel JButton JLabel

3 The JTabbedPane class You can think of a JTabbedPane component as a collection of overlapping tabbed "cards", on which you place other user interface components. A particular card is revealed by clicking on its tab. at the moment the first tab is selected components associated with the other two tabs are kept hidden until the tabs are clicked these components are added to the JPanel the first tabbed component is a JPanel

4 Creating a JTabbedPane // constructor created an empty JTabbedPane JTabbedPane tabs = new JTabbedPane(); // create a JPanel component JPanel controlPanel = new Jpanel(); /* other components can be added to this panel either now or later */ /* add this panel to the JTabbedPane component and give the tab a title */ tabs.addTab("Flight Control", controlPanel,);

5 Both "Flight Arrivals" and "Flight Departures" consist of a text area

6 Adding a JTextArea to a JTabbedPane To add scroll bars to a JTextArea, the JTextArea component has to be added to a JScrollPane component. The JScrollPane is then added to the JTabbedPane as follows: // create text area JTextArea jtaArrivals = new JTextArea(30,20); // add text area to scroll pane JScrollPane jspArrivals = new JScrollPane(jtaArrivals); // add scroll pane to JTabbedPane component tabs.addTab("Flight Arrivals", jspArrivals);

7 Tool Tips A tool tip is an informative description of the purpose of a GUI component. This informative description is revealed when the user places the cursor over the component. We have added tool tips to our buttons.

8 The setToolTipText method Adding a tool tip to a Swing component is easy; just use the setToolTipText method: // create Swing component JButton jbtnBoard = new JButton ("Board"); // add tool tip text jbtnBoard.setToolTipText ("Record a flight as ready for boarding");

9 Short cut keys Ordinarily, a graphical component is selected by clicking on it with a mouse. Sometimes it is convenient to provide keyboard access to such items by means of a short cut. the underlined 'F' indicates that this menu can be selected by pressing ALT-F

10 The setMnemonic method: Creating keyboard short cuts for Swing components is straightforward, just use the setMnemonic method: // create Swing component JMenu fileMenu = new JMenu("File"); // add keyboard shortcut fileMenu.setMnemonic('F');

11 Airport Dialogue Boxes Whenever a button is selected in the "Flight Control" screen, a dialogue box is required to get and process user input.

12 Implementing the Airport Dialogs It makes sense to generalise common features of the dialogue into a base class, AirportDialog, and then use inheritance to develop the specialized dialogue classes: AirportDialog LandingDialogBoardingDialogTakeOffDialogRequestToLandDialogRegisterDialog JDialog Code for all classes are discussed in Charatan and Kans chapter 21.


Download ppt "IM103 week 11 Part 2 P532 Case Study part 2: the Airport GUI Learning objectives By the end of this lecture you should be able to:  use the JTabbedPane."

Similar presentations


Ads by Google