Modern Programming Language Java

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

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Unit 121 A layout manager is an object that determines the manner in which components are arranged in a container. Each layout manager implements one of.
CE203 - Application Programming Autumn 2013CE203 Part 71 Part 7.
Graphical User Interfaces
TCU CoSc Programming with Java Visual Design (Chapter 5)
Java Software Development Paradigm Lecture # 12. Basics of GUI.
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.*;
Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.
LAB SESSION 10 *LAYOUT MANAGER *LISTENERS. Laying the components manually by using a null layout is tedious. Each container object has a layout manager.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
Jan Containers Yangjun Chen Dept. Business Computing University of Winnipeg.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
GUI Layout Managers Arkadiusz Edward Komenda. Outline Components and Containers Layout Managers Flow Layout Grid Layout Border Layout Nested Containers.
GUI and event-driven programming An introduction.
Advanced Java and Android Programming Day 1: Introduction to GUI Programming Intro to GUI Programming1.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
CSE 219 Computer Science III Graphical User Interface.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
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.
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.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Layout Manager Summary
© Marty Hall, Larry Brown, Web core programming 1 Layout Managers Arranging Elements in Windows.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
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.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Csc Basic Graphical User Interface (GUI) Components.
CPSC 233 Tutorial Xin Apr 6, Reading files An example available on my website pages.cpsc.ucalgary.ca/~liuxin.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 14 : Swing II King Fahd University of Petroleum & Minerals College of Computer Science.
J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.
Graphical User Interfaces Tonga Institute of Higher Education.
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.
Lab 4: GUIs, Panels, Mouse and Key Listeners ICOM4015: FALL 2014 A N I NTRODUCTION TO P ANELS AND L AYOUTS CREATED BY KATYA I. BORGOS REVISED BY AMIR H.
 Many event-listener interfaces contain multiple methods.  An adapter class implements an interface and provides a default implementation (with an empty.
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.
Java Layouts CSIS 3701: Advanced Object Oriented Programming.
Java Swing - Lecture 3 Layout Management
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7-3 ( Book Chapter 14) GUI and Event-Driven Programming.
Event Handler Methods Text field Object Responder JAVA AWT Environment: Messages are sent between JAVA Objects Screen Event Notification Press Button.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Dept. of CSIE, National University of Tainan 10/21/2012 Arranging Components on a 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
Christopher Budo, Davis Nygren, spencer franks, Luke miller
Swing JComponents.
Tim McKenna Layout Mangers in Java Tim McKenna
Containers and Components
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
Panels & Layout Managers
GUI building with the AWT
Chapter 7-3 (Book Chapter 14)
GUI Layouts By: Leonard & Saif.
GUI building with the AWT
Layout Organization and Management
Presentation transcript:

Modern Programming Language Java Layout Managers By: Muhammad Haleem

Contents What is Layout Manager? FlowLayout Manager? BorderLayout Manager? GridLayout Manager?

Introduction to Layout Managers Layout managers arrange GUI components in a container for presentation purposes. You can use the layout managers for basic layout capabilities instead of determining every GUI component’s exact position and size. This functionality enables you to concentrate on the basic look-and-feel and lets the layout managers process most of the layout details. Using layout managers to position elements can be simpler and faster than creating a GUI with absolute positioning.

Introduction to Layout Managers A layout manager is an object that governs the positions and sizes of components in a container Swing provides a variety of layouts: FlowLayout, BorderLayout, GridLayout and so on. Use container’s method the setLayout to change its layout container.setLayout(new BorderLayout()) Default layout for JFrame is BorderLayout and FlowLayout for JPanel

What is FlowLayout? Components appear horizontally, from left to right, in the order that they were added. When there is no more room in a row, the next components will be dropped to the next row FlowLayout’s constructors FlowLayout() FlowLayout(int align): the align can be FlowLayout.CENTER, FlowLayout.LEFT, or FlowLayout.RIGHT FlowLayout(int align, int hgap, int vgap) where hgap and vgap are a gap of pixels among components, horizontally and vertically

Designing the View Title: Flow Layout Size: 400x70 Layout: Flow Layout GUI Components: Button 1 Button 2 Button 3

What is BorderLayout? BorderLayout manages five regions where components can be placed

What is BorderLayout? (cont.) BorderLayout’s constructors: BorderLayout BorderLayout(int hgap, int vgap) Components are added to a border layout container: container.add(comp, region) Where the region is one of the following values: BorderLayout.NORTH BorderLayout.SOUTH BorderLayout.EAST BorderLayout.WEST BorderLayout.CENTER

Border Window Problem Develop a program that has interface as below (the frame’s size is 400x300):

Designing the View Title: Border Layout Size: 400x300 Layout: Border Layout GUI Components: North button West button South button East button Center button

Border Panel Window Problem Enhance the border window problem in order to reach the following interface:

Designing the View Title: Border Layout Layout: Border Layout GUI Components: North button panel North button West button panel West button South button panel South button East button panel East button Center button panel Center button

What is GridLayout? GridLayout creates a grid with rows and columns, much like a spreadsheet. A container that is managed by a GridLayout object is divided into equally sized cells Each cell can hold only one component A component that is placed in a cell is automatically resized to fill up any extra space columns rows

What is GridLayout? (cont.) GridLayout’s constructors: GridLayout() GridLayout(int rows, int cols) GridLayout(int rows, int cols, int hgap, int vgap) If rows or cols is declared as zero, it means no limit for rows or columns, but not for both

Grid Window Example Develop a program that has six buttons laid in a grid of 2x3 (The frame’s size is 400x200)

Designing the View Title: Grid Layout Size: 400x200 Layout: Grid Layout (2x3) GUI Components: Six Buttons

Grid Panel Window Example Develop a program that has six labeled buttons laid in a grid as below (the frame’s size is 400x200):

Designing the View Title: Grid Layout Size: 400x200 Layout: Grid Layout (2x3) GUI Components: Button Panel 1 Label: This is cell 1. Button 1 . . . Button Panel 6 Label: This is cell 6. Button 6

Summary Not so difficult but takes a little practice Do not use absolute positioning – because it does not resize well. It should be noted that for absolute positioning of components we have to use the setLayout() with argument null as: setLayout(null) then we will position the component as: component.setBounds(20, 20, 200,20);//x, y, width, hight

Laying out components Use layout managers – basically tells form how to align components when they’re added. Each Container has a layout manager associated with it. A JPanel is a Container – to have different layout managers associated with different parts of a form, tile with JPanels and set the desired layout manager for each JPanel, then add components directly to panels.

Layout Managers Java comes with LayoutManagers. Most common and easiest to use are FlowLayout BorderLayout GridLayout Using just these three it is possible to attain fairly precise layout for most simple applications.

Setting layout managers Very easy to associate a layout manager with a component. Simply call the setLayout method on the Container: JPanel p1 = new JPanel(); p1.setLayout(new FlowLayout(FlowLayout.LEFT)); JPanel p2 = new JPanel(); p2.setLayout(new BorderLayout()); JPanel p3 = new JPanel(); p3.setLayout(new GridLayout(r, c, hgap, vgage));//int As Components are added to the container, the layout manager determines their size and positioning.