SlideShare une entreprise Scribd logo
1  sur  37
  Building Java GUI
Objectives  * Describe the AWT package and its components. * Define the terms  containers ,  components,  and  layout  managers , and how they work together to build a  graphical user interface (GUI)  * Use layout managers * Use the FlowLayout, BorderLayout, GridLayout, and CardLayout managers to achieve a desired dynamic  layout. * Add components to a container * Use the Frame and Panel containers appropriately
* Describe how complex layouts with nested containers  work.  * In a Java program, identify the following: Containers The associated layout managers  The layout hierarchy of all components
  Abstract Window Toolkit (AWT) Provides graphical user interface (GUI) components that are used in all Java applets and application. Contains classes that can be extended and their properties  inherited; classes can also be abstract. Ensures that every GUI component that is displayed on the screen  is a subclass of the abstract class Component or MenuComponent Has Container, which is an abstract subclass of Component  and includes two subclasses:  * Panel * Window
 
Containers * The two main types of containers are Window and  Panel  * A Window is a free floating window on the display * A Panel is a container of GUI components that  must exist in the context of some other container,  such as a window or applet
 
Building Graphical User Interfaces The position and size of a component in a container  is determined by a layout manager. You can control the size or position of components  by disabling the layout manager. You must then use setLocation(), setSize(),or  setBounds() on components to locate them in the  container.
Frames * Are a subclass of Window * Have title and resizing corners * Are initially invisible, use setVisible(true) to expose the  frame * Have BorderLayout as the default layout manager * Use the setLayout method to change the default layout  manager
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
FrameExample.java
[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
FrameWithPanel.java
[object Object],[object Object],[object Object],[object Object],[object Object]
  Default Layout Manager
[object Object],[object Object],[object Object],[object Object],[object Object]
public static void main(String args[]) { LayoutExample guiWindow = new LayoutExample();   guiWindow.launchFrame();   } }
FlowLayoutManager  •  Default layout for the Panel class  •  Components added from left to right •  Default alignment is centered  •  Uses components’ preferred sizes  •  Uses the constructor to tune behavior
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
FlowExample.java
BorderLayoutManager  Default layout for the Frame class Components added to specific regions The resizing behavior: North, South, and Center regions adjust horizontally East, West, and Center regions adjust vertically
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
GridLayoutManager  •  Components are added left to right, top to bottom •  All regions are equally sized  •  The constructor specifies the rows and columns
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
Card Layout   The  CardLayout  class is unique among the other layout managers in that it stores several different layouts. This can be useful for user interfaces with optional components  that can be dynamically enabled and disabled upon user input. The cards are typically held in an object of type  Panel . This panel must have  CardLayout  selected as its layout manager.
[object Object]
[object Object],[object Object],[object Object],[object Object]
lb1 = new Label("This is the first Panel"); lb2 = new Label("This is the second Panel"); lb3 = new Label("This is the third Panel"); lb4 = new Label("This is the fourth Panel"); lb5 = new Label("This is the fifth Panel"); } public void launchFrame() { f.setLayout(myCard); // change the color of each panel, so they are // easily distinguishable p1.setBackground(Color.yellow); p1.add(lb1); p2.setBackground(Color.green); p2.add(lb2); p3.setBackground(Color.magenta); p3.add(lb3); p4.setBackground(Color.white); p4.add(lb4); p5.setBackground(Color.cyan); p5.add(lb5);
// Set up the event handling here. p1.addMouseListener(this); p2.addMouseListener(this); p3.addMouseListener(this); p4.addMouseListener(this); p5.addMouseListener(this); // Add each panel to my CardLayout f.add(p1, "First"); f.add(p2, "Second"); f.add(p3, "Third"); f.add(p4, "Fourth"); f.add(p5, "Fifth"); // Display the first panel. myCard.show(f, "First"); f.setSize(200,200); f.setVisible(true) }
public void mousePressed(MouseEvent e) {  myCard.next(f);  }  public void mouseReleased(MouseEvent e) { }  public void mouseClicked(MouseEvent e) { }  public void mouseEntered(MouseEvent e) { }  public void mouseExited(MouseEvent e) { }  public static void main (String args[]) {  CardExample ct = new CardExample();  ct.launchFrame();  }  }

Contenu connexe

Tendances

Top MNC'S Interview questions and answers
Top MNC'S Interview questions and answersTop MNC'S Interview questions and answers
Top MNC'S Interview questions and answersMadhu Dhare
 
Phoenix for laravel developers
Phoenix for laravel developersPhoenix for laravel developers
Phoenix for laravel developersLuiz Messias
 
AWT Packages , Containers and Components
AWT Packages , Containers and ComponentsAWT Packages , Containers and Components
AWT Packages , Containers and ComponentsSohanur63
 

Tendances (8)

Dbms file
Dbms fileDbms file
Dbms file
 
Top MNC'S Interview questions and answers
Top MNC'S Interview questions and answersTop MNC'S Interview questions and answers
Top MNC'S Interview questions and answers
 
Les09
Les09Les09
Les09
 
Java swing
Java swingJava swing
Java swing
 
Phoenix for laravel developers
Phoenix for laravel developersPhoenix for laravel developers
Phoenix for laravel developers
 
AWT Packages , Containers and Components
AWT Packages , Containers and ComponentsAWT Packages , Containers and Components
AWT Packages , Containers and Components
 
Java swing
Java swingJava swing
Java swing
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 

En vedette

Keep it simple, stupid! w/ speaker notes
Keep it simple, stupid! w/ speaker notesKeep it simple, stupid! w/ speaker notes
Keep it simple, stupid! w/ speaker notesMoritz Rogalli
 
Edward R. Fyfe charity book
Edward R. Fyfe charity bookEdward R. Fyfe charity book
Edward R. Fyfe charity bookmararistina
 
Jody Warnick CV 2014 new
Jody Warnick CV 2014 newJody Warnick CV 2014 new
Jody Warnick CV 2014 newJody Warnick
 
Presentation Smyers
Presentation SmyersPresentation Smyers
Presentation Smyersjmovitt
 
Article review
Article review Article review
Article review kemakamal
 
SONG YU HUI CV UPDATED
SONG YU HUI CV UPDATEDSONG YU HUI CV UPDATED
SONG YU HUI CV UPDATEDSong Yu Hui
 
National Cooperative Month Observed in October
National Cooperative Month Observed in OctoberNational Cooperative Month Observed in October
National Cooperative Month Observed in OctoberCarl Casale
 
Modelos de Gestão de Pessoas em ambiente de fusões e aquisições
Modelos de Gestão de Pessoas em ambiente de fusões e aquisiçõesModelos de Gestão de Pessoas em ambiente de fusões e aquisições
Modelos de Gestão de Pessoas em ambiente de fusões e aquisiçõesAnderson Rafael Brugnera
 
Best Mobile App Development Services in India
Best Mobile App Development Services in IndiaBest Mobile App Development Services in India
Best Mobile App Development Services in IndiaSteve Verma
 
The Real World June 2016
The Real World June 2016The Real World June 2016
The Real World June 2016Posterscope
 
The binomial distributions
The binomial distributionsThe binomial distributions
The binomial distributionsmaamir farooq
 
Docker and Microservice
Docker and MicroserviceDocker and Microservice
Docker and MicroserviceSamuel Chow
 

En vedette (16)

Ricky ortegon
Ricky ortegonRicky ortegon
Ricky ortegon
 
101017cnw2sa
101017cnw2sa101017cnw2sa
101017cnw2sa
 
Keep it simple, stupid! w/ speaker notes
Keep it simple, stupid! w/ speaker notesKeep it simple, stupid! w/ speaker notes
Keep it simple, stupid! w/ speaker notes
 
Lambdas
LambdasLambdas
Lambdas
 
Edward R. Fyfe charity book
Edward R. Fyfe charity bookEdward R. Fyfe charity book
Edward R. Fyfe charity book
 
Jody Warnick CV 2014 new
Jody Warnick CV 2014 newJody Warnick CV 2014 new
Jody Warnick CV 2014 new
 
Presentation Smyers
Presentation SmyersPresentation Smyers
Presentation Smyers
 
Article review
Article review Article review
Article review
 
SONG YU HUI CV UPDATED
SONG YU HUI CV UPDATEDSONG YU HUI CV UPDATED
SONG YU HUI CV UPDATED
 
National Cooperative Month Observed in October
National Cooperative Month Observed in OctoberNational Cooperative Month Observed in October
National Cooperative Month Observed in October
 
Modelos de Gestão de Pessoas em ambiente de fusões e aquisições
Modelos de Gestão de Pessoas em ambiente de fusões e aquisiçõesModelos de Gestão de Pessoas em ambiente de fusões e aquisições
Modelos de Gestão de Pessoas em ambiente de fusões e aquisições
 
Best Mobile App Development Services in India
Best Mobile App Development Services in IndiaBest Mobile App Development Services in India
Best Mobile App Development Services in India
 
The Real World June 2016
The Real World June 2016The Real World June 2016
The Real World June 2016
 
Amul public relation strategy REPORT
Amul public relation strategy REPORTAmul public relation strategy REPORT
Amul public relation strategy REPORT
 
The binomial distributions
The binomial distributionsThe binomial distributions
The binomial distributions
 
Docker and Microservice
Docker and MicroserviceDocker and Microservice
Docker and Microservice
 

Similaire à Md10 building java gu is

Similaire à Md10 building java gu is (20)

09 gui
09 gui09 gui
09 gui
 
09 gui
09 gui09 gui
09 gui
 
09 gui
09 gui09 gui
09 gui
 
LAYOUT.pptx
LAYOUT.pptxLAYOUT.pptx
LAYOUT.pptx
 
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfJEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
 
Chap1 1 4
Chap1 1 4Chap1 1 4
Chap1 1 4
 
Java Graphics Programming
Java Graphics ProgrammingJava Graphics Programming
Java Graphics Programming
 
Chap1 1.4
Chap1 1.4Chap1 1.4
Chap1 1.4
 
ADVANCED JAVA PROGRAMME
ADVANCED JAVA PROGRAMME ADVANCED JAVA PROGRAMME
ADVANCED JAVA PROGRAMME
 
Advance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWTAdvance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWT
 
Oop lecture9 10
Oop lecture9 10Oop lecture9 10
Oop lecture9 10
 
Abstract Window Toolkit
Abstract Window ToolkitAbstract Window Toolkit
Abstract Window Toolkit
 
ch20.pptx
ch20.pptxch20.pptx
ch20.pptx
 
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
 
Final_Project
Final_ProjectFinal_Project
Final_Project
 
GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
 
import java.awt.;class FlowLayoutDemo {    public static void.pdf
import java.awt.;class FlowLayoutDemo {    public static void.pdfimport java.awt.;class FlowLayoutDemo {    public static void.pdf
import java.awt.;class FlowLayoutDemo {    public static void.pdf
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
CORE JAVA-2
 
L11cs2110sp13
L11cs2110sp13L11cs2110sp13
L11cs2110sp13
 

Plus de Rakesh Madugula

Plus de Rakesh Madugula (13)

New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Md121 streams
Md121 streamsMd121 streams
Md121 streams
 
Md11 gui event handling
Md11 gui event handlingMd11 gui event handling
Md11 gui event handling
 
Md09 multithreading
Md09 multithreadingMd09 multithreading
Md09 multithreading
 
Md08 collection api
Md08 collection apiMd08 collection api
Md08 collection api
 
Md07 exceptions&assertion
Md07 exceptions&assertionMd07 exceptions&assertion
Md07 exceptions&assertion
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
 
Md05 arrays
Md05 arraysMd05 arrays
Md05 arrays
 
Md04 flow control
Md04 flow controlMd04 flow control
Md04 flow control
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
 

Dernier

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 

Dernier (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

Md10 building java gu is

  • 1. Building Java GUI
  • 2. Objectives * Describe the AWT package and its components. * Define the terms containers , components, and layout managers , and how they work together to build a graphical user interface (GUI) * Use layout managers * Use the FlowLayout, BorderLayout, GridLayout, and CardLayout managers to achieve a desired dynamic layout. * Add components to a container * Use the Frame and Panel containers appropriately
  • 3. * Describe how complex layouts with nested containers work. * In a Java program, identify the following: Containers The associated layout managers The layout hierarchy of all components
  • 4. Abstract Window Toolkit (AWT) Provides graphical user interface (GUI) components that are used in all Java applets and application. Contains classes that can be extended and their properties inherited; classes can also be abstract. Ensures that every GUI component that is displayed on the screen is a subclass of the abstract class Component or MenuComponent Has Container, which is an abstract subclass of Component and includes two subclasses: * Panel * Window
  • 5.  
  • 6. Containers * The two main types of containers are Window and Panel * A Window is a free floating window on the display * A Panel is a container of GUI components that must exist in the context of some other container, such as a window or applet
  • 7.  
  • 8. Building Graphical User Interfaces The position and size of a component in a container is determined by a layout manager. You can control the size or position of components by disabling the layout manager. You must then use setLocation(), setSize(),or setBounds() on components to locate them in the container.
  • 9. Frames * Are a subclass of Window * Have title and resizing corners * Are initially invisible, use setVisible(true) to expose the frame * Have BorderLayout as the default layout manager * Use the setLayout method to change the default layout manager
  • 10.
  • 12.
  • 13.
  • 14.
  • 16.
  • 17. Default Layout Manager
  • 18.
  • 19. public static void main(String args[]) { LayoutExample guiWindow = new LayoutExample(); guiWindow.launchFrame(); } }
  • 20. FlowLayoutManager • Default layout for the Panel class • Components added from left to right • Default alignment is centered • Uses components’ preferred sizes • Uses the constructor to tune behavior
  • 21.
  • 22.
  • 24. BorderLayoutManager Default layout for the Frame class Components added to specific regions The resizing behavior: North, South, and Center regions adjust horizontally East, West, and Center regions adjust vertically
  • 25.
  • 26.
  • 27.
  • 28. GridLayoutManager • Components are added left to right, top to bottom • All regions are equally sized • The constructor specifies the rows and columns
  • 29.
  • 30.
  • 31.
  • 32. Card Layout The CardLayout class is unique among the other layout managers in that it stores several different layouts. This can be useful for user interfaces with optional components that can be dynamically enabled and disabled upon user input. The cards are typically held in an object of type Panel . This panel must have CardLayout selected as its layout manager.
  • 33.
  • 34.
  • 35. lb1 = new Label("This is the first Panel"); lb2 = new Label("This is the second Panel"); lb3 = new Label("This is the third Panel"); lb4 = new Label("This is the fourth Panel"); lb5 = new Label("This is the fifth Panel"); } public void launchFrame() { f.setLayout(myCard); // change the color of each panel, so they are // easily distinguishable p1.setBackground(Color.yellow); p1.add(lb1); p2.setBackground(Color.green); p2.add(lb2); p3.setBackground(Color.magenta); p3.add(lb3); p4.setBackground(Color.white); p4.add(lb4); p5.setBackground(Color.cyan); p5.add(lb5);
  • 36. // Set up the event handling here. p1.addMouseListener(this); p2.addMouseListener(this); p3.addMouseListener(this); p4.addMouseListener(this); p5.addMouseListener(this); // Add each panel to my CardLayout f.add(p1, "First"); f.add(p2, "Second"); f.add(p3, "Third"); f.add(p4, "Fourth"); f.add(p5, "Fifth"); // Display the first panel. myCard.show(f, "First"); f.setSize(200,200); f.setVisible(true) }
  • 37. public void mousePressed(MouseEvent e) { myCard.next(f); } public void mouseReleased(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public static void main (String args[]) { CardExample ct = new CardExample(); ct.launchFrame(); } }