Components - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Components

Description:

Frames, Panels, Buttons, Labels, TextAreas, TestAreas, ComboBoxes, Lists, ... the screen, synchroniszing it with the display refresh rate to minimize flicker. ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 19
Provided by: philli89
Category:

less

Transcript and Presenter's Notes

Title: Components


1
Components
  • A Java GUI screen is built up using
    components.Frames, Panels, Buttons, Labels,
    TextAreas, TestAreas, ComboBoxes, Lists,
    CheckBoxes, RadioButtons, Borders,
    MessageDialogBoxes, Menus, RadioButtons,
    ScrollBars, ScrollPanes and TabbedPanes.
  • Java Beans are just Java Components that meet
    certain standards. Java Beans can be used in
    other programming languages and in Visual IDEs.
    All of the components listed above are also Java
    Beans.
  • The components listed are all subclasses of the
    Component class and as such they inherit a number
    of properties and methods.

2
Java Beans
  • Components that have been set up as Java Beans
    can be used in Drag and Drop form builders such
    as Borlands JBuilder. They can also be used in
    other languages such as Visual Basic and Delphi.
  • Java Components become Java Beans if they meet
    three minimum requirements.
  • They must be public classes
  • They must have a default constructor.
  • They must implement the Serializable or
    Externalizable interfaces.To be useful they
    should also. . .
  • Provide public access to their properties through
    getter and setter methods.
  • Provide methods for registration to Listeners.

3
Component properties
All GUI objects are subclasses of the awt
Component classand as such inherit these
properties.
Note that Layout managers do not always respect
the last three.
4
JComponent properties
  • Swing components are subclasses of JComponent
    which is itself a subclass of Component. Swing
    components have these additional properties.

5
Components(2)
  • JButton
  • JLabel
  • JTextArea
  • JTextArea
  • JComboBox
  • JList
  • JCheckBox
  • JRadioButton
  • Border
  • JMenuBar
  • JScrollBar
  • JScrollPane
  • JTabbedPane

6
JButton Event Handler ActionListener
7
JLabel Event Handler None
8
JTextField Events TextListener
ActionListener
9
JTextArea Events TextListener
ActionListener
10
JComboBox Events TextListener
ActionListener
11
JList Events TextListener
ActionListener
12
JCheckBox Events ItemListener
ActionListener
13
JRadioButton Events ItemListener
ActionListener
14
Radio Button Groups
Radio buttons are frequently displayed in groups,
only one of which can be selected at a time.
DVD
CD
Tape
Selecting a different one will automatically
de-select the other.Use a ButtonGroup component
as a container. Add the Radio Buttons to it then
add the group to the panelButtonGroup bg new
ButtonGroup() bg.add(radioBut1) bg.add(radioBut2
) bg.add(radioBut3)myPanel.add(bg)
15
Borders
  • Borders with a range of features can be applied
    to any of the JComponents.
  • Border is the superclass for TitledBorder,
    BevelBorder,EtchedBorder, LineBorder, MatteBorder
    and EmptyBorder.
  • Constructor for TitledBorderBorder b new
    TitledBorder(Title)
  • Use the setBorder method of the component to add
    it to the Component

16
BorderFactory
  • A class with static methods to create borders.
  • Some methods are.
  • createTitledBorder(String title)
    createLoweredBevelBorder() createRaisedBevelBord
    er() createLineBorderBorder(Color c) etc. .
    .

17
Message Dialogs
  • Used to Display a simple message and await user
    input before closing.
  • Class JOptionPane has static methods that can be
    called.JOptionPane.showMessageDialog(current
    object, Message
    Line, Box
    title,
    Message_Type)
  • Message type is a static constant in JOPtionBox
  • ERROR_MESSAGEINFORMATION_MESSAGE
    PLAIN_MESSAGE
  • Eg JOptionPane.showMessageDialog(this, You must
    enter a number, Entry Error,JOptionPane.ERROR_
    MESSAGE)

18
Menus
  • There are Three main levels
  • JMenuBar. Create a JMenuBar object and add it to
    the frame.
  • Jmenu. This is the menu object. Create it and add
    it to the MenuBar.
  • JMenuItem. Each element in the menu is a menu
    item. Create each item and add to the menu.
  • Sub menus can be added to a menu like items.
Write a Comment
User Comments (0)
About PowerShow.com