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

Slides:



Advertisements
Similar presentations
G5BUID - Java Swing Laying out components Manage realized components Determine size and position Each container has a layout manager (usually)
Advertisements

Introduction to Java 2 Programming
GUI Elements Session 17. Memory Upload Layout Components Button TextField TextArea Label Choice Containers Panels The applet itself.
Graphical User Interfaces
Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Corresponds with Chapter 12
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
GUI programming AWT(Abstract Windows Toolkit)-GUI components library when Java was introduced AWT was replaced by Swing components import javax.swing.*;
Advanced Java Class GUI – part 1. Intro to GUI GUI = Graphical User Interface -- “Gooey” Just because it’s “gooey” does not mean you may write messy code.
Jan Containers Yangjun Chen Dept. Business Computing University of Winnipeg.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
GUI Layout Managers Arkadiusz Edward Komenda. Outline Components and Containers Layout Managers Flow Layout Grid Layout Border Layout Nested Containers.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
GUI and event-driven programming An introduction.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Layout Managers A layout manager is an object that determines the way that components are arranged in a container There are several predefined layout managers.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
MSc Workshop - © S. Kamin, U.Reddy Lect 5 – GUI Prog - 1 Lecture 5 – GUI Programming r Inner classes  this and super r Layout r Reading: m.
JAPPLET.
Layout Management Containers can arrange their components. Our container is a JPanel, and it can set the way it’s components will be laid out : mypanel.setLayout.
Nov 061 Size Control How is a component’s size determined during layout and during resize operations? Three factors determine component sizes: The component’s.
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Chapter 8: Getting Started with Graphics Programming Graphics Class Hierarchy Graphics Class Hierarchy Frames Frames The relationship between frame and.
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
GUI development in Java L. Grewe Two methodologies for things to appear on the screen 1. By painting / drawing e.g. drawing an Image e.g. drawing an.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Laying Out Components Interior Design for GUIs. Nov 042 What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame’s.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Layout Manager Summary
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
University of Limerick1 Software Architecture Java Layout Managers.
3461 Laying Out Components Interior Design for GUIs.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Review_6 AWT, Swing, ActionListener, and Graphics.
CPSC 233 Tutorial Xin Apr 6, Reading files An example available on my website pages.cpsc.ucalgary.ca/~liuxin.
Java layout managers. import java.awt.*; import java.awt.event.*; import javax.swing.*; class ButtonPanel extends JPanel implements ActionListener { public.
Basics of GUI Programming Chapter 11 and Chapter 22.
AWT Layout Managers (Chapter 10) Java Certification Study Group January 21, 1999 Mark Roth.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 3 Designing the Interface with Layout Managers.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Project Proposals: Due Today!Project Proposals: Due Today! –Identify.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
CSI 3125, Preliminaries, page 1 Layout Managers. CSI 3125, Preliminaries, page 2 Layout Managers The LayoutManagers are used to arrange components in.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Java Layouts CSIS 3701: Advanced Object Oriented Programming.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.
Chapter 7 A First Look at GUI Applications Layout Managers.
Graphical User Interfaces
Modern Programming Language Java
University of Central Florida COP 3330 Object Oriented Programming
Layout Managers A layout manager is an object that determines the way that components are arranged in a container There are several predefined layout managers.
Chapter 13: Advanced GUIs and Graphics
Containers and Components
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
Panels & Layout Managers
GUI Layouts By: Leonard & Saif.
Layout Organization and Management
Advanced GUIs and Graphics
Graphical User Interface
Presentation transcript:

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

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.

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.

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

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.

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

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.

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

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

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

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

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