1 / 21

Graphical User Interface Components

Graphical User Interface Components. The Sequal. Chapter 14. What You Will Learn. Text Areas Sliders Menus With frames Pop up menus Look and feel options. JTextArea. Area for manipulating multiple lines of text Extends JTextComponent Inherits from that class View Figure 14.1

graceland
Download Presentation

Graphical User Interface Components

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graphical User Interface Components The Sequal Chapter 14

  2. What You Will Learn • Text Areas • Sliders • Menus • With frames • Pop up menus • Look and feel options

  3. JTextArea • Area for manipulating multiple lines of text • Extends JTextComponent • Inherits from that class • View Figure 14.1 • Note • Creation of box • Creation of two JTextArea objects • Copy of marked text to other text area

  4. Subclass of JPanel • A JPanel can • Aggregate a set of GUI components • Create dedicated drawing areas • Create areas that receive mouse events • Subclass of a JPanel should • Override method paintComponent • Call the superclass version as first statement • Note the customized JPanel subclass, Figure 14.2

  5. Demonstration of Customized JPanel • Now view Figure 14.3 • Note • Declaration, instantiation of the CustomPanel • Method draw used in actionPerformed methods

  6. Another Customized JPanel Class • Possible for the (sub)class to handle its own events • Note SelfContainedPanel class, Figure 14.4 • This class has • Mouse activity handlers • Preferred dimension specified • Call to paintComponent method • Figure 14.5 uses this customized subclass

  7. tick mark JSliders • Enable users to select from range of integer values • Features • Tick marks (major and minor) • Snap-to ticks • Orientation (horizontal and vertical) thumb

  8. JSliders • JPanel subclass for drawing circles, Figure 14.7 • JSlider used to control size of a circle graphic, Figure 14.8 • Note • Slider declaration, implementation • Registration of listener for the slider

  9. Using Menus with Frames • Allows for performing actions with cluttering GUI • Contained by menu bar – JMenuBar • Comprised of menu items – MenuItem • Note Figure 14.9 • Declares menu items • Populates the menus • Specifies actions for menu choices

  10. JPopupMenu • Menus that are context-sensitive • Right click and popup menu appears • In Swing, use JPopupMenu • Provide options specific to component • Popup trigger event occurs when object right mouse clicked • Demonstration of JPopupMenu shown in Figure 14.10

  11. Pluggable Look-and-Feel • Recall that Java is designed to run on variety of platforms • GUI components on a Mac, look different from those on a PC or on a UNIX platform • Look-and-Feel capability • Java program on a particular platform looks like other programs on the same platform • Also possible to specify the look-and-feel of a Swing GUI

  12. Pluggable Look-and-Feel • Figure 14.11 demonstrates how to change the appearance • Note use of UIManager methods

  13. JDesktopPane and JInternalFrame • Multiple document interface • Main (parent) window • Child windows • View Figure 14.12 which demonstrates this • Note • Declaration, instantiation of JDesktopPane object • Choosing and painting of the icons

  14. JTabbedPane • Arranges GUI components into layers • One layer visible at a time • Access each layer via a tab • View tab demo program, Figure 14.13 • Note • declaration of tabbed panes

  15. Layout Managers • BoxLayout arranges GUI components • Horizontally along x-axis • Vertically along y-axis

  16. BoxLayout • Demonstrated in Figure 14.15 • Also uses the tabs • Offers several different options for laying out three JButtons • Note • Creation of boxes • Adding of buttons

  17. GridBagLayout Layout Manager • Flexible GridBagLayout • Components can vary in size • Components can occupy multiple rows and columns • Components can be added in any order • Uses GridBagConstraints • Specifies how component is placed in GridBagLayout

  18. GridBagLayout Layout Manager • GridBagConstraints fields

  19. GridBagLayout Layout Manager • Designing a GUI to use the GridBagLayout • Program for this layout demonstrated in Figure 14.19 Column 0 1 2 0 1 Row 2 3

  20. GridBagLayout Layout Manager • Variation of GridBagLayoutdoes not use gridx and gridy • Use constants RELATIVE and REMAINDER • RELATIVE • Specifies next-to-last component placement in row or column • Component placed next to one previously added • REMAINDER • Specifies component as last component in row or column

  21. GridBagLayout Layout Manager • Use of constraints demonstrated inFigure 14.20 • Note • Setting constraint weights • Setting grid width • Adding buttons • The addComponent method

More Related