15
Java Programming Abstract Windows Toolkit (AWT) Prof. Shailesh Gahane Assistant Professor Dr. D. Y. Patil School of MCA Charholi (Bk), Lohegaon, Pune – 412105 Mail ID: [email protected] Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Abstract Windows Toolkit (awt)

Embed Size (px)

DESCRIPTION

Abstract Windows Toolkit 3.1 Components and Graphics 3.2 Containers, Frames and Panels 3.3 Layout Managers 3.4 Border layout, Flow layout, Grid layout, Card layout 3.5 AWT all components Event delegation Model Event source and handler Event categories, Listeners, interfaces Anonymous classes, Adapter Classes Swing Libraries Model view Controller design pattern Different layout, menus dialog boxes, text input

Citation preview

Page 1: Abstract Windows Toolkit (awt)

Java ProgrammingAbstract Windows

Toolkit (AWT)

Prof. Shailesh GahaneAssistant Professor

Dr. D. Y. Patil School of MCACharholi (Bk), Lohegaon, Pune – 412105Mail ID: [email protected]

Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 2: Abstract Windows Toolkit (awt)

ABSTRACT WINDOWS TOOLKIT (AWT) AND SWING

AWT and Swing Controls begins with an examination of the standard controls and layout managers. It includes menus and the menu bar also.

Controls are components that allow a user to interact with your application in various ways.

A layout manager automatically positions components within a container. Thus, the appearance of a window is determined by a combination of the controls that it contains and the layout manager used to position them.

Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 3: Abstract Windows Toolkit (awt)

The AWT supports the following types of controls:

• Labels• Push buttons or Button• Check boxes• Choice lists• Lists• Scroll bars• Text editing and many more…These controls are subclasses of

Component.

Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 4: Abstract Windows Toolkit (awt)

A label is an object of type Label, and it contains a string, which it displays. Labels are passive controls that do not support any interaction with the user.

Constructors of class Label: Label( ) throws HeadlessException Label(String str) throws HeadlessException Label(String str, int how) throws HeadlessException A push button is a component that contains a label

and that generates an event when it is pressed. Push buttons are objects of type Button.

Button defines these two constructors: Button( ) throws HeadlessException Button(String str) throws HeadlessException1The first version creates an empty button. The second

creates a button that contains str as a label.Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 5: Abstract Windows Toolkit (awt)

CHECK BOX A check box is a control that is used to turn an

option on or off. Check boxes are objects of the Checkbox class. Checkbox supports these constructors: Checkbox( ) throws HeadlessException Checkbox(String str) throws HeadlessException Checkbox(String str, boolean on) throws

HeadlessException Checkbox(String str, boolean on, CheckboxGroup

cbGroup) throws HeadlessException Checkbox(String str, CheckboxGroup cbGroup,

boolean on) throws HeadlessException

Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 6: Abstract Windows Toolkit (awt)

CheckboxGroup or Radio Button These check boxes are often called radio buttons,

because they act like the station selector on a car radio—only one station can be selected at any one time.

Check box groups are objects of type CheckboxGroup. You can determine which check box in a group is currently selected by calling getSelectedCheckbox( ). You can set a check box by calling setSelectedCheckbox( ).

These methods are as follows: Checkbox getSelectedCheckbox( ) void setSelectedCheckbox(Checkbox which) Here, which is the check box that you want to

be selected. The previously selected check box will be turned off.Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 7: Abstract Windows Toolkit (awt)

INTRODUCING SWING Swing uses the same event handling

mechanism as the AWT. Therefore, a basic understanding of the AWT and of event handling is required to use Swing.

The swing has two key features: lightweight components and a pluggable look and feel

lightweight components are more efficient and more flexible.

The look and feel of each component is determined by Swing, not by the underlying operating system.

It is possible to “plug in” a new look and feel for any given component without creating any side effects in the code that uses that component.Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 8: Abstract Windows Toolkit (awt)

Swing also supports innovative tools like Layout Managers, Graphics debugging, Mouse less operations and many more.

Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 9: Abstract Windows Toolkit (awt)

Swing components are derived from the JComponent class.

JComponent provides the functionality that is common to all components.

All of Swing’s components are represented by classes defined within the package javax.swing.

JApplet , JButton JCheckBox JCheckBoxMenuItemJColorChooser JComboBox JComponent JDesktopPaneJDialog JEditorPane JFileChooser JFormattedTextFieldJFrame JInternalFrame JLabel JLayeredPaneJList JMenu JMenuBar JMenuItemJOptionPane JPanel JPasswordField JPopupMenuJProgressBar JRadioButton JRadioButtonMenuItem

JRootPane JScrollBar JScrollPane JSeparator JSliderJSpinner JSplitPane JTabbedPane JTableJTextArea JTextField JTextPane JTogglebuttonJToolBar JToolTip JTree Jviewport JWindowProf. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 10: Abstract Windows Toolkit (awt)

Model View Control Architecture The Model View Controller Architecture is the

heart of the Swing User Interface Component.

Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 11: Abstract Windows Toolkit (awt)

In MVC terminology, the “MODEL” corresponds to the state information associated with the component. Ex: check box, the model contains a field that indicates if the box is checked or unchecked.

The “VIEW” determines how the component is displayed on the screen, including any aspects of the view that are affected by the current state of the model. Ex: Visual Effect seen to the user.

The “CONTROLLER” determines how the component reacts to the user. Ex: handles the input such as mouse click.Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 12: Abstract Windows Toolkit (awt)

LAYOUT MANAGERS IN JAVA The arrangement of components within a

containers, Layout manager can be used. A layout manager automatically arranges your controls within a window.

Each Container object has a layout manager.

A Layout manager is an instance of any class that implements of any class that implements the LayoutManager interface.

The Layout manager is set by the setLayout() method.

Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 13: Abstract Windows Toolkit (awt)

Java defines the five Layout managers.1. FlowLayout 2. GridLayout 3. BorderLayout 4. CardLayout5. GridbagLayout

1) FlowLayout: Places components in successive rows in a container, fitting as many on each row as possible and starting on the next row as soon as a row is full. It is the default layout manager for JPanel object.

2) BorderLayout: Places components against any of the four borders. The component in the center fills the available space. This layout manager is the default for the content Pane in a JFram, JDialog or JAppletProf. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 14: Abstract Windows Toolkit (awt)

3) CardLayout: places components in a container one on top of the other.

4) GridLayout: Places components in the container in a rectangular grid with the no. of rows and columns that you specify.

5) GridBagLayout: This also places the components into an arrangement of rows and columns, but the rows and columns can vary in length.

Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Page 15: Abstract Windows Toolkit (awt)

Thank you !!!

Prof. Shailesh T. Gahane, Dr. D Y Patil School of MCA, Pune

Prof. Shailesh GahaneAssistant Professor

Dr. D. Y. Patil School of MCACharholi (Bk), Lohegaon, Pune – 412105Mail ID: [email protected]