SlideShare a Scribd company logo
09 GUIsHUREE University ICTInstructor: M.J LEE
ContentsAbstract Window ToolkitContainerFramePanelLayout ManagerFlow LayoutBorder LayoutGrid Layout2
AWT(Abstract Window Toolkit)AWT: the group of classes for GUI in Java3Java.awt.*
Component / ContainerFrame4import java.awt.*; public class MyFrameextends Frame { 	public MyFrame (String str) { 	super(str); } public class MyFrameMain {	public static void main (String args[]) { MyFramefr = new MyFrame(“It’s frame!"); fr.setSize(500,500); fr.setBackground(Color.blue); fr.setVisible(true); 	} }12“is a relation” MyFrame is Frame3Create containerSet the size of frame45Set the background Color:Color is Class
PanelUse add() method, when adding componentsPanel can’t be displayed by itself. Therefore, it should be included in FrameSome components are disposed in Panel by Layout Manager5
6import java.awt.*; public class FrameWithPanelextends Frame { 	public FrameWithPanel (String str) { 		super(str); 	} }Public class FrameWithPanelMain() {	public static void main (String args[]) {FrameWithPanelfr = new FrameWithPanel(“Panel in Frame");		Panel pan = new Panel();  fr.setSize(200,200); 		// a framefr.setBackground(Color.blue); fr.setLayout(null);  pan.setSize(100,100); 		// a panelpan.setBackground(Color.yellow);  fr.add(pan);   // put the panel in the framefr.setVisible(true); } }Panel
Layout ManagerFlowLayout	Panel, default Layout manager of AppletBorderLayout	Window, default Layout manager of FrameGridLayoutCardLayoutGridBagLayout7
8import java.awt.*; public class ExGui { 	private Frame f; 		// declarationFrame	private Button b1; 	// declaration Button	private Button b2;	public void go() { 		f = new Frame("GUI example"); f.setLayout(new FlowLayout()); 	b1 = new Button(“Yes”); 	b2 = new Button(“No"); f.add(b1); 		// append Button on Framef.add(b2); f.pack(); 		// instead of “.setSize()”f.setVisible(true); 	} }public static ExGuiMain() {	public static void main(String args[]) { ExGuiguiWindow = new ExGui(); guiWindow.go(); 	}}1. Flow Layout
Layout Manager –1.Flow LayoutAt above example, which didn't inherit Frame, declared new frame in the classProperties, Flow Layout Manageris a default layout manager of Paneldepose components from left to right!depose components at the middle of Frame, as defaultdecide the size of components by itselfIt is possible to exchange attributes by using constructor9setLayout(new FlowLayout(FlowLayout.RIGHT, 20, 40))
Layout Manager –1.Flow LayoutComponents are disposed at right side.Gap of left and right between componentsGap of top and bottom between components (unit: pixel)10setLayout(new FlowLayout(FlowLayout.RIGHT, 20, 40))123
11import java.awt.*; public class MyFlow { 	private Frame f; 	private Button button1, button2, button3; 	public void go() { 		f = new Frame("Flow Layout");f.setLayout(new FlowLayout()); 		button1 = new Button("Ok"); 			button2 = new Button("Open"); 			button3 = new Button("Close"); 					f.add(button1); f.add(button2); f.add(button3); f.setSize(100,100); f.setVisible(true);	} }Public class MyFlowMain() {	public static void main(String args[]) { MyFlowmflow = new MyFlow(); mflow.go(); 	} } 1. Flow Layout
12import java.awt.*;public class ExGui2 { 	private Frame f; 	private Button bn, bs, bw, be, bc; 	public void go() { 		f = new Frame("Border Layout"); bn = new Button("B1");bs = new Button("B2");bw = new Button("B3");be = new Button("B4");bc = new Button("B5");f.add(bn, BorderLayout.NORTH); f.add(bs, BorderLayout.SOUTH); f.add(bw, BorderLayout.WEST);f.add(be, BorderLayout.EAST);f.add(bc, BorderLayout.CENTER); f.setSize(200,200);f.setVisible(true);	} 	public static void main(String args[]) { 		ExGui2 guiWindow2 = new ExGui2(); 		guiWindow2.go(); 	}}2. Border Layout
132. Grid Layoutimport java.awt.*; public class TestGrid { 	private Frame f;	private Button b1, b2, b3, b4, b5, b6;	public void go() { 	f = new Frame(“Grid Layout");f.setLayout (new GridLayout(3,2));b1 = new Button("1");b2 = new Button("2");b3 = new Button("3");b4 = new Button("4"); b5 = new Button("5");b6 = new Button("6"); f.add(b1); f.add(b2);f.add(b3);f.add(b4);f.add(b5);f.add(b6);f.pack();f.setVisible(true); 	} 	public static void main(String args[]) { TestGrid grid = new TestGrid(); grid.go(); 	}}
Layout Manager –3.Grid LayoutAdd(): components are disposed from left to right, upside to bottomThe size of each cell, which is divided by Grid Layout Manager, is same.The number of cells can be defined when they are created with Constructor.f.setLayout (new GridLayout(3,2));14

More Related Content

PPT
Md10 building java gu is
DOCX
Assignment 2 lab 3 python gpa calculator
PPT
Drawing Figures
PDF
Oopsprc1e
PPT
Asp sales dec v2.6
PPTX
09 gui
PPT
Pie Bellies, Colonoscopies and the Doorway of Forgetfulness - Structuring Use...
Md10 building java gu is
Assignment 2 lab 3 python gpa calculator
Drawing Figures
Oopsprc1e
Asp sales dec v2.6
09 gui
Pie Bellies, Colonoscopies and the Doorway of Forgetfulness - Structuring Use...

Similar to 09 gui (20)

PPTX
LAYOUT.pptx
PDF
import java.awt.;class FlowLayoutDemo {    public static void.pdf
PPTX
Awt, Swing, Layout managers
PDF
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
PPT
java2 swing
PDF
Getting started with GUI programming in Java_1
PPT
Unit4 AWT, Swings & Layouts power point presentation
PPT
Oop lecture9 10
PPTX
ADVANCED JAVA PROGRAMME
PPTX
Abstract Window Toolkit_Event Handling_python
PPT
Chap1 1 4
PPT
GWT Training - Session 2/3
PPT
Java_gui_with_AWT_and_its_components.ppt
PPT
Awt and swing in java
PPTX
Advanced Java programming
PPTX
it's about the swing programs in java language
PPTX
swings.pptx
PDF
Abstract Window Toolkit
DOCX
Final_Project
LAYOUT.pptx
import java.awt.;class FlowLayoutDemo {    public static void.pdf
Awt, Swing, Layout managers
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
java2 swing
Getting started with GUI programming in Java_1
Unit4 AWT, Swings & Layouts power point presentation
Oop lecture9 10
ADVANCED JAVA PROGRAMME
Abstract Window Toolkit_Event Handling_python
Chap1 1 4
GWT Training - Session 2/3
Java_gui_with_AWT_and_its_components.ppt
Awt and swing in java
Advanced Java programming
it's about the swing programs in java language
swings.pptx
Abstract Window Toolkit
Final_Project
Ad

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Approach and Philosophy of On baking technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
Teaching material agriculture food technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Programs and apps: productivity, graphics, security and other tools
MYSQL Presentation for SQL database connectivity
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
MIND Revenue Release Quarter 2 2025 Press Release
NewMind AI Weekly Chronicles - August'25 Week I
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectroscopy.pptx food analysis technology
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Understanding_Digital_Forensics_Presentation.pptx
Spectral efficient network and resource selection model in 5G networks
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
20250228 LYD VKU AI Blended-Learning.pptx
Teaching material agriculture food technology
Review of recent advances in non-invasive hemoglobin estimation
Dropbox Q2 2025 Financial Results & Investor Presentation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Ad

09 gui

  • 1. 09 GUIsHUREE University ICTInstructor: M.J LEE
  • 2. ContentsAbstract Window ToolkitContainerFramePanelLayout ManagerFlow LayoutBorder LayoutGrid Layout2
  • 3. AWT(Abstract Window Toolkit)AWT: the group of classes for GUI in Java3Java.awt.*
  • 4. Component / ContainerFrame4import java.awt.*; public class MyFrameextends Frame { public MyFrame (String str) { super(str); } public class MyFrameMain { public static void main (String args[]) { MyFramefr = new MyFrame(“It’s frame!"); fr.setSize(500,500); fr.setBackground(Color.blue); fr.setVisible(true); } }12“is a relation” MyFrame is Frame3Create containerSet the size of frame45Set the background Color:Color is Class
  • 5. PanelUse add() method, when adding componentsPanel can’t be displayed by itself. Therefore, it should be included in FrameSome components are disposed in Panel by Layout Manager5
  • 6. 6import java.awt.*; public class FrameWithPanelextends Frame { public FrameWithPanel (String str) { super(str); } }Public class FrameWithPanelMain() { public static void main (String args[]) {FrameWithPanelfr = new FrameWithPanel(“Panel in Frame"); Panel pan = new Panel();  fr.setSize(200,200); // a framefr.setBackground(Color.blue); fr.setLayout(null);  pan.setSize(100,100); // a panelpan.setBackground(Color.yellow);  fr.add(pan); // put the panel in the framefr.setVisible(true); } }Panel
  • 7. Layout ManagerFlowLayout Panel, default Layout manager of AppletBorderLayout Window, default Layout manager of FrameGridLayoutCardLayoutGridBagLayout7
  • 8. 8import java.awt.*; public class ExGui { private Frame f; // declarationFrame private Button b1; // declaration Button private Button b2; public void go() { f = new Frame("GUI example"); f.setLayout(new FlowLayout()); b1 = new Button(“Yes”); b2 = new Button(“No"); f.add(b1); // append Button on Framef.add(b2); f.pack(); // instead of “.setSize()”f.setVisible(true); } }public static ExGuiMain() { public static void main(String args[]) { ExGuiguiWindow = new ExGui(); guiWindow.go(); }}1. Flow Layout
  • 9. Layout Manager –1.Flow LayoutAt above example, which didn't inherit Frame, declared new frame in the classProperties, Flow Layout Manageris a default layout manager of Paneldepose components from left to right!depose components at the middle of Frame, as defaultdecide the size of components by itselfIt is possible to exchange attributes by using constructor9setLayout(new FlowLayout(FlowLayout.RIGHT, 20, 40))
  • 10. Layout Manager –1.Flow LayoutComponents are disposed at right side.Gap of left and right between componentsGap of top and bottom between components (unit: pixel)10setLayout(new FlowLayout(FlowLayout.RIGHT, 20, 40))123
  • 11. 11import java.awt.*; public class MyFlow { private Frame f; private Button button1, button2, button3; public void go() { f = new Frame("Flow Layout");f.setLayout(new FlowLayout()); button1 = new Button("Ok"); button2 = new Button("Open"); button3 = new Button("Close"); f.add(button1); f.add(button2); f.add(button3); f.setSize(100,100); f.setVisible(true); } }Public class MyFlowMain() { public static void main(String args[]) { MyFlowmflow = new MyFlow(); mflow.go(); } } 1. Flow Layout
  • 12. 12import java.awt.*;public class ExGui2 { private Frame f; private Button bn, bs, bw, be, bc; public void go() { f = new Frame("Border Layout"); bn = new Button("B1");bs = new Button("B2");bw = new Button("B3");be = new Button("B4");bc = new Button("B5");f.add(bn, BorderLayout.NORTH); f.add(bs, BorderLayout.SOUTH); f.add(bw, BorderLayout.WEST);f.add(be, BorderLayout.EAST);f.add(bc, BorderLayout.CENTER); f.setSize(200,200);f.setVisible(true); } public static void main(String args[]) { ExGui2 guiWindow2 = new ExGui2(); guiWindow2.go(); }}2. Border Layout
  • 13. 132. Grid Layoutimport java.awt.*; public class TestGrid { private Frame f; private Button b1, b2, b3, b4, b5, b6; public void go() { f = new Frame(“Grid Layout");f.setLayout (new GridLayout(3,2));b1 = new Button("1");b2 = new Button("2");b3 = new Button("3");b4 = new Button("4"); b5 = new Button("5");b6 = new Button("6"); f.add(b1); f.add(b2);f.add(b3);f.add(b4);f.add(b5);f.add(b6);f.pack();f.setVisible(true); } public static void main(String args[]) { TestGrid grid = new TestGrid(); grid.go(); }}
  • 14. Layout Manager –3.Grid LayoutAdd(): components are disposed from left to right, upside to bottomThe size of each cell, which is divided by Grid Layout Manager, is same.The number of cells can be defined when they are created with Constructor.f.setLayout (new GridLayout(3,2));14