windows programming with swing

37
IADCS Diploma Course Swing Programming U Nyein Oo U Nyein Oo COO/Director(IT) COO/Director(IT) Myanma Computer Co., Myanma Computer Co.,

Upload: backdoor

Post on 20-Nov-2014

3.111 views

Category:

Business


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Windows Programming with Swing

IADCS Diploma CourseSwing Programming

U Nyein OoU Nyein Oo

COO/Director(IT)COO/Director(IT)

Myanma Computer Co.,Myanma Computer Co.,

Page 2: Windows Programming with Swing

Copyright: MCC Swing Programming 2

Java Foundation Classes?

Set of Java Class Libraries provides as part of J2SE

Support building GUI and graphics functionality for Java based Client Application

Run on Microsoft Platform and others like Mac OSX and Linux

Easily deployed over the web Rich clients for web services

Page 3: Windows Programming with Swing

Copyright: MCC Swing Programming 3

Features of JFC

Abstract Windowing Toolkits Java 2D Swing GUI Components Accessibility Internationalization

Page 4: Windows Programming with Swing

Copyright: MCC Swing Programming 4

MVC Architecture

Design pattern to Swing UI for JFC Used for constructing entire UI Components Each component has a Model, a View and a

Controller. The model, view ,and controller pieces can

change even while the component is in use.

Page 5: Windows Programming with Swing

Copyright: MCC Swing Programming 5

MVC Design Pattern

Model

ControllerView

Inform the view to update visual

Read the contents

Update the contentsInform view of

state change

Page 6: Windows Programming with Swing

Copyright: MCC Swing Programming 6

What MVC means?

Model is the piece that represents the state and low level behavior of the component.

(stored the data or stage of object) View is the piece that manage the visual

display of the state represented by the model Controller is the piece that manages user

interaction with the model.(handle the event)

Page 7: Windows Programming with Swing

Copyright: MCC Swing Programming 7

Benefits using MVC

To divded large program to views of documents.

A view provides a window into document Multiple views can provide multiple windows

into the document.

Page 8: Windows Programming with Swing

Copyright: MCC Swing Programming 8

Swing Programming

AWT is the heave weight component and it has a peer object for the native GUI

When the components are created they take help of the underlying O/S

Java offers Light weight components that do not have a peer object.

It now popular by Swing UI components

Page 9: Windows Programming with Swing

Copyright: MCC Swing Programming 9

Why Swing?

Uses fewer system resources Add a lot of more sophisticated components Tailor the Look and Feel of program and Extensing of Existing Components for

- Layout Management

- Event handling

- Thread and Swing

- Printing ….etc

Page 10: Windows Programming with Swing

Copyright: MCC Swing Programming 10

Swing Basic

Swing is set of packages build on top of the AWT with number of prebuild classes(over 250 classes and 40UI components)

All swing UI components are started with J for use the terms JFC and Swing interchangeabily

Page 11: Windows Programming with Swing

Copyright: MCC Swing Programming 11

Structure of Swing Components

JContainer Classes

JComponent Classes

All Swing Components

Page 12: Windows Programming with Swing

Copyright: MCC Swing Programming 12

Swing Components

Windows Menus AbstractButton Panels Layouts Icons Borders Toolbars

Labels Buttons List Boxes Combo Boxes Check Boxes Tables Trees

Page 13: Windows Programming with Swing

Copyright: MCC Swing Programming 13

Sub Classes of the JComponent Class

JComponent is the superclass of all swing components. All the components begin with the letter ‘J’. JComponent has the following subclasses:

– AbstractButton class – JButton & JLabel class – JButton – JLabel – JComboBox class – JCheckBox class – Jlist– Jmenu– JPopupMenu– JProgressBar– JScrollBar

– JRadioButton– Jseparator– Jtable– JTextComponent– JToolBar– JTree

Page 14: Windows Programming with Swing

Copyright: MCC Swing Programming 14

Swing PackagesSwing Package Description

javax.swing Contains components, adapters, component models and interfaces. It is the highest-level swing package.

javax.swing.basic Contains the user interface classes that implement the look and feel for swing components.

javax.swing.border Declares the border interface, and classes defining the specific border styles.

javax.swing.plaf Contains the plugable look and feel API.

javax.swing.table Contains the interfaces and classes supporting the swing table component.

javax.swing.text Contains the support classes for the swing document framework.

javax.swing.event Defines the events and event listeners.

javax.swing.tree Provides classes and interfaces that support the JTree component.

javax.swing.undo Provides support classes for undo/redo operations.

Page 15: Windows Programming with Swing

Copyright: MCC Swing Programming 15

Swing Event Handling

For a Java program to run, the interface should be made receptive to user events

Swing handles events with a set of classes called ‘event listeners’

javax.swing.event package defines a set of event listening interfaces and event classes so that they can used with Swing components

There are various events defined in the javax.swing.event package, such as:

– ChangeEvent – DragEvent – ListDataEvent

ListSelectionEvent TableModelEvent TableColumnEvent

Page 16: Windows Programming with Swing

Copyright: MCC Swing Programming 16

Look and Feel

Swing is a real improvement to the AWT, since it supplies rich set of platform GUI components

Platform independence means the components within it are supported across all Java ports

Enables the look and feel of the components to be easily tailored

This is called as Pluggable Look and Feel (L&F) of the swing components

This helps us to create applets and applications that have a look and feel independent to the window platform in which they are executed

Page 17: Windows Programming with Swing

Copyright: MCC Swing Programming 17

Look and Feel Cont;

The look and feel consists of the way the program is presented to the user (looks) & the way user interacts with it (feels).

Swing provides the capability to change the look and feel of the applet or application.

Swing components are not tied to GUI components. It is because of this that we can create applets or applications that will use a specific look and feel. Look and feel is a function of view and controller.

Page 18: Windows Programming with Swing

Copyright: MCC Swing Programming 18

Thank You

Page 19: Windows Programming with Swing

Copyright: MCC Swing Programming 19

1. Frame Test

Page 20: Windows Programming with Swing

Copyright: MCC Swing Programming 20

3. Label Test

Page 21: Windows Programming with Swing

Copyright: MCC Swing Programming 21

4. Button Test

Page 22: Windows Programming with Swing

Copyright: MCC Swing Programming 22

6. Text Area Test

Page 23: Windows Programming with Swing

Copyright: MCC Swing Programming 23

7. CheckBox and Radio Button

Page 24: Windows Programming with Swing

Copyright: MCC Swing Programming 24

8. Listtest Test

Page 25: Windows Programming with Swing

Copyright: MCC Swing Programming 25

9. Color Change Test

Page 26: Windows Programming with Swing

Copyright: MCC Swing Programming 26

10. Editable TextArea Test

Page 27: Windows Programming with Swing

Copyright: MCC Swing Programming 27

11. Border Test

Page 28: Windows Programming with Swing

Copyright: MCC Swing Programming 28

12. Calcuator

Page 29: Windows Programming with Swing

Copyright: MCC Swing Programming 29

13. Combo Example

Page 30: Windows Programming with Swing

Copyright: MCC Swing Programming 30

14. Menu Example

Page 31: Windows Programming with Swing

Copyright: MCC Swing Programming 31

15. Popup Menu Example

Page 32: Windows Programming with Swing

Copyright: MCC Swing Programming 32

16. DialogBox Test

Page 33: Windows Programming with Swing

Copyright: MCC Swing Programming 33

17. Table Test

Page 34: Windows Programming with Swing

Copyright: MCC Swing Programming 34

18. Progress Bar Test

Page 35: Windows Programming with Swing

Copyright: MCC Swing Programming 35

19. Tooltips Test

Page 36: Windows Programming with Swing

Copyright: MCC Swing Programming 36

20. Color Chooser Test

Page 37: Windows Programming with Swing

Copyright: MCC Swing Programming 37

21. File Chooser Test