09 GUIs<br />HUREE University ICT<br />Instructor: M.J LEE<br />
Contents<br />Abstract Window Toolkit<br />Container<br />Frame<br />Panel<br />Layout Manager<br />Flow Layout<br />Borde...
AWT(Abstract Window Toolkit)<br />AWT: the group of classes for GUI in Java<br />3<br /><ul><li>Java.awt.*
Component / Container</li></li></ul><li>Frame<br />4<br />import java.awt.*; <br />public class MyFrameextends Frame { <br...
Panel<br />Use add() method, when adding components<br />Panel can’t be displayed by itself. Therefore, it should be inclu...
6<br />import java.awt.*; <br />public class FrameWithPanelextends Frame { <br />	public FrameWithPanel (String str) { <br...
Layout Manager<br />FlowLayout<br />	Panel, default Layout manager of Applet<br />BorderLayout<br />	Window, default Layou...
8<br />import java.awt.*; <br />public class ExGui { <br />	private Frame f; 		// declarationFrame<br />	private Button b1...
Layout Manager –1.Flow Layout<br />At above example, which didn't inherit Frame, declared new frame in the class<br />Prop...
Layout Manager –1.Flow Layout<br />Components are disposed at right side.<br />Gap of left and right between components<br...
11<br />import java.awt.*; <br />public class MyFlow { <br />	private Frame f; <br />	private Button button1, button2, but...
12<br />import java.awt.*;<br />public class ExGui2 { <br />	private Frame f; <br />	private Button bn, bs, bw, be, bc; <b...
13<br />2. Grid Layout<br />import java.awt.*; <br />public class TestGrid { <br />	private Frame f;<br />	private Button ...
Layout Manager –3.Grid Layout<br />Add(): components are disposed from left to right, upside to bottom<br />The size of ea...
Upcoming SlideShare
Loading in …5
×

09 gui

740 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
740
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

09 gui

  1. 1. 09 GUIs<br />HUREE University ICT<br />Instructor: M.J LEE<br />
  2. 2. Contents<br />Abstract Window Toolkit<br />Container<br />Frame<br />Panel<br />Layout Manager<br />Flow Layout<br />Border Layout<br />Grid Layout<br />2<br />
  3. 3. AWT(Abstract Window Toolkit)<br />AWT: the group of classes for GUI in Java<br />3<br /><ul><li>Java.awt.*
  4. 4. Component / Container</li></li></ul><li>Frame<br />4<br />import java.awt.*; <br />public class MyFrameextends Frame { <br /> public MyFrame (String str) { <br /> super(str); <br />} <br />public class MyFrameMain {<br /> public static void main (String args[]) { <br />MyFramefr = new MyFrame(“It’s frame!"); <br />fr.setSize(500,500); <br />fr.setBackground(Color.blue); <br />fr.setVisible(true); <br /> } <br />}<br />1<br />2<br />“is a relation”<br /> MyFrame is Frame<br />3<br />Create container<br />Set the size of frame<br />4<br />5<br />Set the background Color:Color is Class<br />
  5. 5. Panel<br />Use add() method, when adding components<br />Panel can’t be displayed by itself. Therefore, it should be included in Frame<br />Some components are disposed in Panel by Layout Manager<br />5<br />
  6. 6. 6<br />import java.awt.*; <br />public class FrameWithPanelextends Frame { <br /> public FrameWithPanel (String str) { <br /> super(str); <br /> } <br />}<br />Public class FrameWithPanelMain() {<br /> public static void main (String args[]) {<br />FrameWithPanelfr = new FrameWithPanel(“Panel in Frame");<br /> Panel pan = new Panel(); <br /> <br />fr.setSize(200,200); // a frame<br />fr.setBackground(Color.blue); <br />fr.setLayout(null); <br /> <br />pan.setSize(100,100); // a panel<br />pan.setBackground(Color.yellow); <br /> <br />fr.add(pan); // put the panel in the frame<br />fr.setVisible(true); <br />} <br />}<br />Panel<br />
  7. 7. Layout Manager<br />FlowLayout<br /> Panel, default Layout manager of Applet<br />BorderLayout<br /> Window, default Layout manager of Frame<br />GridLayout<br />CardLayout<br />GridBagLayout<br />7<br />
  8. 8. 8<br />import java.awt.*; <br />public class ExGui { <br /> private Frame f; // declarationFrame<br /> private Button b1; // declaration Button<br /> private Button b2;<br /> public void go() { <br /> f = new Frame("GUI example"); <br />f.setLayout(new FlowLayout()); <br /> b1 = new Button(“Yes”); <br /> b2 = new Button(“No"); <br />f.add(b1); // append Button on Frame<br />f.add(b2); <br />f.pack(); // instead of “.setSize()”<br />f.setVisible(true); <br /> } <br />}<br />public static ExGuiMain() {<br /> public static void main(String args[]) { <br />ExGuiguiWindow = new ExGui(); <br />guiWindow.go(); <br /> }<br />}<br />1. Flow Layout<br />
  9. 9. Layout Manager –1.Flow Layout<br />At above example, which didn't inherit Frame, declared new frame in the class<br />Properties, Flow Layout Manager<br />is a default layout manager of Panel<br />depose components from left to right!<br />depose components at the middle of Frame, as default<br />decide the size of components by itself<br />It is possible to exchange attributes by using constructor<br />9<br />setLayout(new FlowLayout(FlowLayout.RIGHT, 20, 40))<br />
  10. 10. Layout Manager –1.Flow Layout<br />Components are disposed at right side.<br />Gap of left and right between components<br />Gap of top and bottom between components (unit: pixel)<br />10<br />setLayout(new FlowLayout(FlowLayout.RIGHT, 20, 40))<br />1<br />2<br />3<br />
  11. 11. 11<br />import java.awt.*; <br />public class MyFlow { <br /> private Frame f; <br /> private Button button1, button2, button3; <br /> public void go() { <br /> f = new Frame("Flow Layout");<br />f.setLayout(new FlowLayout()); <br /> button1 = new Button("Ok"); <br /> button2 = new Button("Open"); <br /> button3 = new Button("Close"); f.add(button1); <br />f.add(button2); <br />f.add(button3); <br />f.setSize(100,100); <br />f.setVisible(true);<br /> } <br />}<br />Public class MyFlowMain() {<br /> public static void main(String args[]) { <br />MyFlowmflow = new MyFlow(); <br />mflow.go(); <br /> } <br />} <br />1. Flow Layout<br />
  12. 12. 12<br />import java.awt.*;<br />public class ExGui2 { <br /> private Frame f; <br /> private Button bn, bs, bw, be, bc; <br /> public void go() { <br /> f = new Frame("Border Layout"); <br />bn = new Button("B1");<br />bs = new Button("B2");<br />bw = new Button("B3");<br />be = new Button("B4");<br />bc = new Button("B5");<br />f.add(bn, BorderLayout.NORTH); <br />f.add(bs, BorderLayout.SOUTH); <br />f.add(bw, BorderLayout.WEST);<br />f.add(be, BorderLayout.EAST);<br />f.add(bc, BorderLayout.CENTER); <br />f.setSize(200,200);<br />f.setVisible(true);<br /> } <br /> public static void main(String args[]) { <br /> ExGui2 guiWindow2 = new ExGui2(); <br /> guiWindow2.go(); <br /> }<br />}<br />2. Border Layout<br />
  13. 13. 13<br />2. Grid Layout<br />import java.awt.*; <br />public class TestGrid { <br /> private Frame f;<br /> private Button b1, b2, b3, b4, b5, b6;<br /> public void go() { <br /> f = new Frame(“Grid Layout");<br />f.setLayout (new GridLayout(3,2));<br />b1 = new Button("1");<br />b2 = new Button("2");<br />b3 = new Button("3");<br />b4 = new Button("4"); <br />b5 = new Button("5");<br />b6 = new Button("6"); <br />f.add(b1); <br />f.add(b2);<br />f.add(b3);<br />f.add(b4);<br />f.add(b5);<br />f.add(b6);<br />f.pack();<br />f.setVisible(true); <br /> } <br /> public static void main(String args[]) { <br />TestGrid grid = new TestGrid(); <br />grid.go(); <br /> }<br />}<br />
  14. 14. Layout Manager –3.Grid Layout<br />Add(): components are disposed from left to right, upside to bottom<br />The size of each cell, which is divided by Grid Layout Manager, is same.<br />The number of cells can be defined when they are created with Constructor.<br />f.setLayout (new GridLayout(3,2));<br />14<br />

×