SlideShare uma empresa Scribd logo
1 de 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();  }  }

Mais conteúdo relacionado

Mais procurados

Phoenix for laravel developers
Phoenix for laravel developersPhoenix for laravel developers
Phoenix for laravel developers
Luiz Messias
 

Mais procurados (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
 

Destaque

Jody Warnick CV 2014 new
Jody Warnick CV 2014 newJody Warnick CV 2014 new
Jody Warnick CV 2014 new
Jody Warnick
 
SONG YU HUI CV UPDATED
SONG YU HUI CV UPDATEDSONG YU HUI CV UPDATED
SONG YU HUI CV UPDATED
Song Yu Hui
 
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
Anderson 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 India
Steve Verma
 

Destaque (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
 

Semelhante a Md10 building java gu is

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
MarlouFelixIIICunana
 

Semelhante a 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
 

Mais de Rakesh Madugula

Mais 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
 

Último

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Último (20)

Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
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
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

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(); } }