1 / 14

Layout, Components, & Data Entry

Learn about different layout managers in Java, including BorderLayout, FlowLayout, BoxLayout, and GridLayout. Explore data entry components such as CheckBoxDemo, RadioButtonDemo, ComboBoxDemo, and TextFieldDemo.

klang
Download Presentation

Layout, Components, & Data Entry

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. Layout, Components, & Data Entry Appendix C.3-C.5

  2. Layout Managers • BorderLayout • Arranges objects in five areas of the container. • FlowLayout • Arranges objects in left-to-right order. • BoxLayout • Arranges objects in a single row or column. • GridLayout • Arranges objects in a two-dimensional grid.

  3. BorderLayout • Default layout for JFrame’s content pane. • 5 areas (N,S,E,W,Center) • Don’t have to fill out all areas. • See Listing and Example. • Be sure to use Java reference. • Java Reference Document • Remember to look up class hierarchy. • Use Index. • Find setBorder? • Constants.

  4. FlowLayout • Left to Right until maximum width. • Dimension for array size. • PreferredSize (20, 20). • Show resize of window. • Last line centered if not full. • Use setAlignment to change order. • See Listing and Example.

  5. BoxLayout • Horizontal or Vertical arrangement. • BoxLayout.X_AXIS • BozLayout.Y_AXIS • Components don’t wrap. • See Listing and Example. • What’s missing from this code? • (Hint: related to buttons.)

  6. GridLayout • Rectangular grid. • Fixed Size (set by setLayout(new GridLayout( 5,10) ) • 5 rows and 10 columns. • See Listing and Example. • Note Integer.toString (conversion method) • Factories described on page 183.

  7. Combining Layouts • Lab #3 (Programming #2, page 785)

  8. Components for Data Entry • So what does a good GUI do? • Enable the user to provide input data to an application. • Enable the user to control the action of the application. • Display information or results to the user. • Are there any “bad” Guis? • Web Pages That Suck  Poor Design • Interface Hall Of Shame  Shame

  9. CheckBoxDemo • Multiple selections possible. • Check mark shows selection. • See Listing and Example. • Note listeners.

  10. RadioButtonDemo • Only one selection possible. • Old time “radio buttons”, press one and it resets the others. • See Listing and Example. • Note selections.length used to control number of buttons. • Also, note the loop to define buttons.

  11. ComboBoxDemo • Selections shown by text. • Drop-down list. • See Listing and Example • Note, no loop.

  12. TextFieldDemo • Label and field to type in. • See Listing and Example. • Note NumberEntered uses an exception.

  13. Example Data Entry in a GUI • VolumeConverterGUI • Fairly complicated constructor. • Enter in one field, output in the other. • Notice how the gui is built-up in layers. • JFrame’s content pane set to a 2x2 grid. • The grid contains labels and text boxes. • Two files to look at. • See Listing and Example.

  14. CurrencyDemo • An example of querrying “where am I”? • Using the Java locale.

More Related