SlideShare una empresa de 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();  }  }

Más contenido relacionado

La actualidad más candente

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

La actualidad más candente (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
 

Destacado

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
 

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

Similar 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
 

Similar 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
 

Más de Rakesh Madugula

Más 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

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
kauryashika82
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
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)

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
 
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
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.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
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
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"
 
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
 
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
 
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...
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).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
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 

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