GUI Programming   in Java Presented by Thanh Pham [email_address] 06/2007 B070038 – NIIT Quang Trung Because Learning Never Stop!
Contents Basic Concepts 1 AWT and Swing Control Components 2 Layout Manager 3 Event Handling 4 Other References 5
Basic Concepts Basic Concepts Exercises Demos AWT  vs. Swing GUI?
GUI? Graphical User Interface (pronounced "GOO-ee“). Presents a user-friendly mechanism for interacting with an application. Users can learn how to use an app quickly and use it more productively. Ex: Internet Explorer, MS Word, JCreator… GUIs are built from  GUI components  (controls or widgets-window gadget). A GUI component is an object with which the user interacts via the mouse, the keyboard or another form of input, such as voice recognition.
Abstract Window Toolkit (AWT) vs. Swing Similarities: Tools provided by Java for developing interactive GUI applications Provides GUI components that can be used in creating Java applications and applets
Abstract Window Toolkit (AWT) vs. Swing AWT (Abstract Window Toolkit) Some AWT components use native code Platform-dependent Ensure that the look and feel of an application run on different machines be comparable Swing Written entirely using the Java programming language Platform-independent Ensures applications deployed across different platforms have the same appearance Built around a number of APIs that implement various parts of the AWT Can be used with AWT
Demo MessageBox InputBox Create Frame (AWT) Create Frame (Swing) CenterFrame
Exercises Display two input-boxes that accepts two numbers then shows the result. Accepts three numbers, displays the largest, smallest. (Assume that all input values are valid numbers) Create a simple frame
AWT and Swing Control Components AWT and Swing Control Components Exercises Demos Swing AWT
AWT Control Components An AWT control is a component that enables end users to interact with applications created in Java.  All AWT controls in Java are subclasses of the Component class.  The Component class provides the add() method to add AWT components to containers, such as an applet or a window.
AWT Control Components TextField TextArea Button List CheckBox Choice Labels
Demo FrameWithControl
Swing Control Components Swing components contain the Pluggable Look and Feel (PL&F) feature that allows applications to have the same behavior on various platforms.  Identifying the Swing Component Class Hierarchy The JComponent class is the root of the Swing hierarchy, which is an extension of the AWT container class.  The class hierarchy of the Swing components is categorized into:  Top-level Swing Containers: Acts as a container  for placing the intermediate-level and atomic swing components, such as panels, frames, buttons, and check boxes.  Intermediate-level Swing Containers: Placed on the top-level containers and contains atomic components. Atomic Components: Placed on the intermediate-level swing containers. Atomic components are used  to accept input from a user.
Swing Control Components Using the Top-level Swing Containers JApplet The JApplet class is an extension of the AWT applet class.  The Swing components that contain an applet need to extend the JApplet class. The JApplet() constructor  enables you to create a swing applet instance when you create an instance of the JApplet class. JFrame: The JFrame class is an extension of the AWT Frame class.  You cannot add components directly to JFrame.
Swing Control Components Using the Top-level Swing Containers (Cont.) JDialog The JDialog class is an extension of the AWT java.awt.Dialog class. Using the Intermediate Level Swing Containers JPanel JPanel class is an extension of the JComponent class that provides a replacement for the AWT Panel class.  You create a panel and add various components to it.  The panel is further added to the content pane, which represents the display area of a window, a dialog, or a frame.  JPanel supports all layout managers of AWT.  By default, JPanel applies the flow layout manager.
Swing Control Components Using the Intermediate Level Swing Containers (Contd.) JTabbedPane: The JTabbedPane class is used to create a tabbed pane component that enables you to switch between groups of components by clicking a tab with a given label.  Tabs are added to the JTabbedPane object by using the addTab() method.  The JTabbedPane class enables you to add multiple components but it displays only a single component at a time. Using the Atomic Components JButton JTextField  JCheckBox  JComboBox  JLabel  JRadioButton
Demo JFrameWithControl
Exercises
Layout Managers Layout Managers Demo Grid Layout Border  Layout Flow Layout
Layout Managers The layout managers are used to position the components, such as an applet, a panel, or a frame in a container.  The layout managers implement the  java.awt.LayoutManager  interface.  A layout manager is an instance of the  LayoutManager  interface in Java.  You can use the following method to apply the desired layout to the components:  void setLayout(layoutManager obj)   In the preceding syntax, obj is the reference to the desired layout manager.  Java has various predefined classes of layout managers.  All layout managers make use of the  setLayout()  method to set the layout of a container.  If the  setLayout()  method is not used, then the default layout of the container is set.
Layout Managers The different types of layout managers are: FlowLayout Manager  The flow layout is the default layout manager used for the Applet class.  In the flow layout manager, the components are placed in a container window in a sequence one after the other in rows.  Java provides the FlowLayout class to apply flow layout to the various components that you are inserting in an applet.  You can use the following constructors to create an instance of the FlowLayout class:  FlowLayout() FlowLayout(int align) FlowLayout(int align, int hgap,int vgap)
Layout Managers BorderLayout Manager BorderLayout is the default layout of the Frame class.  The BorderLayout layout manager divides the container into north, south, east, west, and centre regions.  You can place five components or controls in each part. Java provides the BorderLayout class to apply the border layout to the components.  The setLayout() method is used for applying border layout to a container.  You specify the directions for the BorderLayout using the BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST, BorderLayout.WEST, and BorderLayout.CENTER constants.  You can use the following constructors to create an instance of the BorderLayout class: BorderLayout() BorderLayout(int h, int v)
Layout Managers GridLayout Manager  The grid layout is the layout that divides the container into rows and columns.  The intersection of a row and a column of the grid layout is called cell.  The GridLayout class of Java enables you to create a grid layout.  All the components in a grid are of the same size.  You can use the following constructors to create an instance of the GridLayout class:  GridLayout() GridLayout(int r, int c) GridLayout(int r, int c, int h, int v)
Demo FlowLayout BorderLayout GridLayout
To be continued To be continued….
References Java Passion from Sun Microsystems Java Tutorial from Sun Microsystems Core Java 2 Volume I Fundamentals 7 th  Edition Java How to Program 6 th  Edition Java Swing 2 nd  Edition
www.niit-vn.com www.niit-vn.com/4rum Thank You !

More Related Content

PPT
Java: GUI
PPTX
Java awt (abstract window toolkit)
PPTX
GUI components in Java
PPTX
C# classes objects
PPTX
Java Server Pages(jsp)
PPTX
Java packages
PPT
Generics in java
PPT
Files in c++ ppt
Java: GUI
Java awt (abstract window toolkit)
GUI components in Java
C# classes objects
Java Server Pages(jsp)
Java packages
Generics in java
Files in c++ ppt

What's hot (20)

PPT
PPTX
Applets in java
PDF
JAVA GUI PART I
PPTX
Html Frames
PPTX
Inheritance in JAVA PPT
PDF
PPTX
Inheritance in java
PDF
Android datastorage
PPTX
Android Services
PPTX
Lecture 1 introduction to vb.net
PPT
C++ classes tutorials
PPTX
Chapter 3 servlet & jsp
PPTX
Interfaces in java
PPTX
Java swing
PPT
Introduction to Javascript
PPT
Basic concept of OOP's
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPTX
Interface in java
PDF
Basics of JavaScript
PPTX
Static keyword ppt
Applets in java
JAVA GUI PART I
Html Frames
Inheritance in JAVA PPT
Inheritance in java
Android datastorage
Android Services
Lecture 1 introduction to vb.net
C++ classes tutorials
Chapter 3 servlet & jsp
Interfaces in java
Java swing
Introduction to Javascript
Basic concept of OOP's
Basic Concepts of OOPs (Object Oriented Programming in Java)
Interface in java
Basics of JavaScript
Static keyword ppt
Ad

Viewers also liked (20)

PPTX
GUI Programming in JAVA (Using Netbeans) - A Review
PPT
Java Swing
PPSX
Basic of Java Netbeans
PPTX
Graphical User Interface (Gui)
PPT
Swing and Graphical User Interface in Java
PDF
PPT
Netbeans IDE & Platform
PPT
Java swing
PPTX
Introduction to java netbeans
PPT
Graphical User Interface (GUI) - 1
PDF
java swing tutorial for beginners(java programming tutorials)
PPT
java swing
PDF
JAVA GUI PART III
PPT
Swing and AWT in java
PPTX
Java Swing
PPT
Text field and textarea
PPTX
GUI programming
PPTX
PPT
Java swings
PPT
java swing programming
GUI Programming in JAVA (Using Netbeans) - A Review
Java Swing
Basic of Java Netbeans
Graphical User Interface (Gui)
Swing and Graphical User Interface in Java
Netbeans IDE & Platform
Java swing
Introduction to java netbeans
Graphical User Interface (GUI) - 1
java swing tutorial for beginners(java programming tutorials)
java swing
JAVA GUI PART III
Swing and AWT in java
Java Swing
Text field and textarea
GUI programming
Java swings
java swing programming
Ad

Similar to GUI Programming In Java (20)

PPTX
MODULE 5.pptx gui programming and applets
PDF
Ajp notes-chapter-01
PDF
Java awt tutorial javatpoint
PPTX
Java AWT and Java FX
PPTX
JAVA (UNIT 5)
PPT
Chap1 1 1
PPT
Chap1 1.1
PPTX
Java_Unit6pptx__2024_04_13_18_18_07.pptx
PPT
Windows Programming with Swing
PDF
Ajp notes-chapter-01
PPT
Unit4 AWT, Swings & Layouts power point presentation
PPTX
Computer Programming NC III - Java Swing.pptx
DOC
java swing notes in easy manner for UG students
PPTX
AWT.pptx
PDF
Java swing 1
PDF
Abstract Window Toolkit
PPTX
Chapter 1 swings
PPTX
JAVA SWING PPT FOR PROGRAMMING AND CODING
MODULE 5.pptx gui programming and applets
Ajp notes-chapter-01
Java awt tutorial javatpoint
Java AWT and Java FX
JAVA (UNIT 5)
Chap1 1 1
Chap1 1.1
Java_Unit6pptx__2024_04_13_18_18_07.pptx
Windows Programming with Swing
Ajp notes-chapter-01
Unit4 AWT, Swings & Layouts power point presentation
Computer Programming NC III - Java Swing.pptx
java swing notes in easy manner for UG students
AWT.pptx
Java swing 1
Abstract Window Toolkit
Chapter 1 swings
JAVA SWING PPT FOR PROGRAMMING AND CODING

More from yht4ever (12)

PPTX
Applications of SOA and Web Services in Grid Computing
PPT
ERD - Database Design
PPT
Web Page Authoring 1
PPT
Introduction to HTML
PPT
Introduction to HTML
PPT
Document Object Model
PPT
XPath - XML Path Language
PPT
Rendering XML Document
PPT
Rendering XML Documents
PPT
XML Schema
PPT
Document Type Definition
PPT
Introduction to XML
Applications of SOA and Web Services in Grid Computing
ERD - Database Design
Web Page Authoring 1
Introduction to HTML
Introduction to HTML
Document Object Model
XPath - XML Path Language
Rendering XML Document
Rendering XML Documents
XML Schema
Document Type Definition
Introduction to XML

Recently uploaded (20)

PPT
What is a Computer? Input Devices /output devices
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PPT
Module 1.ppt Iot fundamentals and Architecture
DOCX
Basics of Cloud Computing - Cloud Ecosystem
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PPTX
Training Program for knowledge in solar cell and solar industry
PPT
Geologic Time for studying geology for geologist
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PPTX
Build Your First AI Agent with UiPath.pptx
PPTX
Configure Apache Mutual Authentication
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
Five Habits of High-Impact Board Members
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
What is a Computer? Input Devices /output devices
Flame analysis and combustion estimation using large language and vision assi...
UiPath Agentic Automation session 1: RPA to Agents
OpenACC and Open Hackathons Monthly Highlights July 2025
Module 1.ppt Iot fundamentals and Architecture
Basics of Cloud Computing - Cloud Ecosystem
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
Training Program for knowledge in solar cell and solar industry
Geologic Time for studying geology for geologist
sustainability-14-14877-v2.pddhzftheheeeee
Getting started with AI Agents and Multi-Agent Systems
Comparative analysis of machine learning models for fake news detection in so...
Convolutional neural network based encoder-decoder for efficient real-time ob...
Build Your First AI Agent with UiPath.pptx
Configure Apache Mutual Authentication
Final SEM Unit 1 for mit wpu at pune .pptx
Custom Battery Pack Design Considerations for Performance and Safety
Five Habits of High-Impact Board Members
A proposed approach for plagiarism detection in Myanmar Unicode text

GUI Programming In Java

  • 1. GUI Programming in Java Presented by Thanh Pham [email_address] 06/2007 B070038 – NIIT Quang Trung Because Learning Never Stop!
  • 2. Contents Basic Concepts 1 AWT and Swing Control Components 2 Layout Manager 3 Event Handling 4 Other References 5
  • 3. Basic Concepts Basic Concepts Exercises Demos AWT vs. Swing GUI?
  • 4. GUI? Graphical User Interface (pronounced "GOO-ee“). Presents a user-friendly mechanism for interacting with an application. Users can learn how to use an app quickly and use it more productively. Ex: Internet Explorer, MS Word, JCreator… GUIs are built from GUI components (controls or widgets-window gadget). A GUI component is an object with which the user interacts via the mouse, the keyboard or another form of input, such as voice recognition.
  • 5. Abstract Window Toolkit (AWT) vs. Swing Similarities: Tools provided by Java for developing interactive GUI applications Provides GUI components that can be used in creating Java applications and applets
  • 6. Abstract Window Toolkit (AWT) vs. Swing AWT (Abstract Window Toolkit) Some AWT components use native code Platform-dependent Ensure that the look and feel of an application run on different machines be comparable Swing Written entirely using the Java programming language Platform-independent Ensures applications deployed across different platforms have the same appearance Built around a number of APIs that implement various parts of the AWT Can be used with AWT
  • 7. Demo MessageBox InputBox Create Frame (AWT) Create Frame (Swing) CenterFrame
  • 8. Exercises Display two input-boxes that accepts two numbers then shows the result. Accepts three numbers, displays the largest, smallest. (Assume that all input values are valid numbers) Create a simple frame
  • 9. AWT and Swing Control Components AWT and Swing Control Components Exercises Demos Swing AWT
  • 10. AWT Control Components An AWT control is a component that enables end users to interact with applications created in Java. All AWT controls in Java are subclasses of the Component class. The Component class provides the add() method to add AWT components to containers, such as an applet or a window.
  • 11. AWT Control Components TextField TextArea Button List CheckBox Choice Labels
  • 13. Swing Control Components Swing components contain the Pluggable Look and Feel (PL&F) feature that allows applications to have the same behavior on various platforms. Identifying the Swing Component Class Hierarchy The JComponent class is the root of the Swing hierarchy, which is an extension of the AWT container class. The class hierarchy of the Swing components is categorized into: Top-level Swing Containers: Acts as a container for placing the intermediate-level and atomic swing components, such as panels, frames, buttons, and check boxes. Intermediate-level Swing Containers: Placed on the top-level containers and contains atomic components. Atomic Components: Placed on the intermediate-level swing containers. Atomic components are used to accept input from a user.
  • 14. Swing Control Components Using the Top-level Swing Containers JApplet The JApplet class is an extension of the AWT applet class. The Swing components that contain an applet need to extend the JApplet class. The JApplet() constructor enables you to create a swing applet instance when you create an instance of the JApplet class. JFrame: The JFrame class is an extension of the AWT Frame class. You cannot add components directly to JFrame.
  • 15. Swing Control Components Using the Top-level Swing Containers (Cont.) JDialog The JDialog class is an extension of the AWT java.awt.Dialog class. Using the Intermediate Level Swing Containers JPanel JPanel class is an extension of the JComponent class that provides a replacement for the AWT Panel class. You create a panel and add various components to it. The panel is further added to the content pane, which represents the display area of a window, a dialog, or a frame. JPanel supports all layout managers of AWT. By default, JPanel applies the flow layout manager.
  • 16. Swing Control Components Using the Intermediate Level Swing Containers (Contd.) JTabbedPane: The JTabbedPane class is used to create a tabbed pane component that enables you to switch between groups of components by clicking a tab with a given label. Tabs are added to the JTabbedPane object by using the addTab() method. The JTabbedPane class enables you to add multiple components but it displays only a single component at a time. Using the Atomic Components JButton JTextField JCheckBox JComboBox JLabel JRadioButton
  • 19. Layout Managers Layout Managers Demo Grid Layout Border Layout Flow Layout
  • 20. Layout Managers The layout managers are used to position the components, such as an applet, a panel, or a frame in a container. The layout managers implement the java.awt.LayoutManager interface. A layout manager is an instance of the LayoutManager interface in Java. You can use the following method to apply the desired layout to the components: void setLayout(layoutManager obj) In the preceding syntax, obj is the reference to the desired layout manager. Java has various predefined classes of layout managers. All layout managers make use of the setLayout() method to set the layout of a container. If the setLayout() method is not used, then the default layout of the container is set.
  • 21. Layout Managers The different types of layout managers are: FlowLayout Manager The flow layout is the default layout manager used for the Applet class. In the flow layout manager, the components are placed in a container window in a sequence one after the other in rows. Java provides the FlowLayout class to apply flow layout to the various components that you are inserting in an applet. You can use the following constructors to create an instance of the FlowLayout class: FlowLayout() FlowLayout(int align) FlowLayout(int align, int hgap,int vgap)
  • 22. Layout Managers BorderLayout Manager BorderLayout is the default layout of the Frame class. The BorderLayout layout manager divides the container into north, south, east, west, and centre regions. You can place five components or controls in each part. Java provides the BorderLayout class to apply the border layout to the components. The setLayout() method is used for applying border layout to a container. You specify the directions for the BorderLayout using the BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST, BorderLayout.WEST, and BorderLayout.CENTER constants. You can use the following constructors to create an instance of the BorderLayout class: BorderLayout() BorderLayout(int h, int v)
  • 23. Layout Managers GridLayout Manager The grid layout is the layout that divides the container into rows and columns. The intersection of a row and a column of the grid layout is called cell. The GridLayout class of Java enables you to create a grid layout. All the components in a grid are of the same size. You can use the following constructors to create an instance of the GridLayout class: GridLayout() GridLayout(int r, int c) GridLayout(int r, int c, int h, int v)
  • 25. To be continued To be continued….
  • 26. References Java Passion from Sun Microsystems Java Tutorial from Sun Microsystems Core Java 2 Volume I Fundamentals 7 th Edition Java How to Program 6 th Edition Java Swing 2 nd Edition