Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tim McKenna Seneca@York Layout Mangers in Java Tim McKenna Seneca@York.

Similar presentations


Presentation on theme: "Tim McKenna Seneca@York Layout Mangers in Java Tim McKenna Seneca@York."— Presentation transcript:

1 Tim McKenna Seneca@York
Layout Mangers in Java Tim McKenna

2 Layout Managers A container (JPanel) has a layout manager. A layout manager is an object that manages the size and location of the components inside a container.

3 Layout Managers A top-level container (JFrame) has a "content pane" which can be set to a container (JPanel). This container can contain other containers. Containers can be associated with different layout managers.

4 Containment Hierarchy
a logical hierarchy of containers nest containers inside other containers JPanel (inside JPanel …) inside JFrame advantages a more organized, cleaner GUI layout new components can be added to one container without affecting the other containers programming technique: use of panels inside panels, each with different layouts

5 Use of Panels Components are grouped into different containers, i.e. JPanels Each container uses its own layout manager to position components. Another container uses its layout manager to position the panels.

6 Three Common Layout Managers
java.awt.FlowLayout java.awt.BorderLayout java.awt.GridLayout

7 FlowLayout Manager default for panels and applets
locations: from left to right, from top to bottom alignment and spacing Example: FlowLayoutManager.java Exercise: Resize the window and see how the components flow.

8 BorderLayout Manager default for JFrame window objects
locations marked by 5 areas: NORTH, SOUTH, EAST, WEST, CENTER each area can contain only ONE object, usually a JPanel object sizing of the areas: NORTH, SOUTH: horizontal expansion EAST, WEST: vertical expansion CENTER: flows Example: BorderLayoutManager.java

9 GridLayout Manager locations: a grid of rows and columns
size of the components: equal size Example: GridLayoutManager.java Example: LayoutManagers.java

10 Graphics Programming in Java
drawing methods(API): java.awt.Graphics java.awt.Graphics2D (Java 2) Colors: java.awt.Color Fonts: java.awt.Font

11 Graphics Programming in Java
Java’s coordinate system: - upper-left corner of a GUI component: (0,0) pixel coordinates A Graphics object manages a graphics context for drawing

12 Displaying Methods for the AWT Component Class
the paint () method the repaint () method => update () method: the background is erased => paint () method programming: override the paint () method Example: MouseDemo.java


Download ppt "Tim McKenna Seneca@York Layout Mangers in Java Tim McKenna Seneca@York."

Similar presentations


Ads by Google