Download presentation
Presentation is loading. Please wait.
1
Advanced Java Class GUI, part 2
2
JComponent methods addXXXListener(XXXListener) repaint() – [optional arguments: delay and coordinates of sub-area to repaint] setBackground(Color) setForeground(Color) setBorder(Border) setEnabled(boolean) setFont(Font) setPreferredSize(Dimension) & setSize(Dimension) setToolTipText(String) setVisible(boolean)
3
Containers Containers have Components inside them. The arrangement of the components is arranged by a LayoutManager. Some types of Containers: –Windows: top-level elements that may be placed anywhere on the screen. No menu bars or title bars. Frames: top-level windows that also have title bars and menu bars Dialog: gets information from user. –belongs to a Frame –can be modal or not (prevents other interaction with application while it’s open) –Panels: generic containers, which must be inside a window of some type.
4
Labels, Buttons, and Icons JLabels: shows some text AbstractButton –JButtons: push button with text label –JToggleButtons: stays down after one push, comes back up after another. Has text label. JCheckBox: usually more than one can be selected at a time. JRadioButton: placed in ButtonGroups so that only one may be selected at any given time. –JMenuItem: goes in a menu: see next slide ImageIcon: shows an icon
5
Menus JMenuBar: –goes at the top of a JFrame –contains menus JMenu: –goes in a JMenuBar –contains JMenuItems and JSeparators JMenuItem: –goes in a JMenu –can have an icon and/or a text label –you can set an Action on it (see slides on Actions) Two subtypes: JCheckBoxMenuItem & JRadioButtonMenuItem JPopUpMenu: a menu that is not tied to a MenuBar
6
Representing a range, rather than a fixed list of items Sliders: User can move a slider along a line to choose a value Spinners: User gets arrows to go through possible values ProgressBars: Shows percent progress, as in file down loads ScrollBars: Controls what part of contents is currently in the view.
7
Text Entry JTextField (for shorter amounts of text) –JPasswordField –JFormattedTextField JTextArea (for longer amounts of text) JTextPane (for longer amounts of text, with graphical mark up capabilities that JTextArea doesn’t have)
8
Complex Components Choosers: –JColorChooser: lets user pick a color –JFileChooser: lets user pick a file Data Structure Representations: –JTable: graphical representation of a table. –JTree: graphical representation of a tree structure. –Both have their own package and Model classes.
9
Printing java.awt.print.PrinterJob –to obtain one, call PrinterJob.getPrinterJob() –uses PageFormat objects to control formatting –uses Printable objects to do the printing –uses Pageable objects as documents –can print, cancel, setCopies, optionally give the user a dialog box, etc. (Don’t use old java.awt.PrinterJob class!)
10
Example No task here See the SwingExample class for a visual description of several of these GUI classes
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.