Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.

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
LayoutManager, J 1 Layout Manager. LayoutManager, J 2 Layout Manager To each UI container there is a layout manager (an object). When you add a component.
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.
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.
Java GUI building with the AWT. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many.
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.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
1 Why layout managers Can we perform layout without them? –Yes. A container’s layout property can be set to null. Absolute positioning: specify size and.
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 Managers Arranges and lays out the GUI components on a container.
Layout Manager Summary
© Marty Hall, Larry Brown, Web core programming 1 Layout Managers Arranging Elements in Windows.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
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.
Csc Basic Graphical User Interface (GUI) Components.
J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
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.
Graphical User Interfaces (GUI). PART ONE About GUI’s.
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 Swing - Lecture 3 Layout Management
Event Handler Methods Text field Object Responder JAVA AWT Environment: Messages are sent between JAVA Objects Screen Event Notification Press Button.
User Interface Components. Layout Placement of UI components in a window – Size & Position Each component occupies a rectangular region in the window.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
Session 10. Java Simplified / Session 10 / 2 of 36  An Applet is a Java program that can be executed with the help of a Java enabled browser.  Every.
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.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
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.
Swing JComponents.
Modern Programming Language Java
University of Central Florida COP 3330 Object Oriented Programming
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Containers and Components
Tim McKenna Layout Mangers in Java Tim McKenna
Panels & Layout Managers
LayoutManagers The LayoutManagers are used to arrange components in a particular manner. LayoutManager is an interface that is implemented by all the classes.
GUI building with the AWT
Layout Organization and Management
Advanced GUIs and Graphics
Presentation transcript:

Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12

Rina Overview LayoutManagers FlowLayout BoarderLayout GridLayout

Rina LayoutManager The LayoutManager class lets you control the locations of individual components in Java applets. Since you're never sure how big an area you'll have to work with or how it will be shaped, most of the controls are relative in nature. java.awt.LayoutManager is an interface that defines the interface for classes that know how to lay out Containers.

Rina LayoutManager Five classes in the java packages implement java.awt.LayoutManager: –FlowLayout –BorderLayout –CardLayout –GridLayout –GridBagLayout In simple applets with just a few components you often need only one layout manager.

Rina FlowLayout A FlowLayout arranges components from left to right until there's no more space left. Then it begins a row lower and moves from left to right again. It is a default layout. Each component in a FlowLayout gets as much space as it needs and no more. A FlowLayout is useful for laying out buttons but not for much else.

Rina FlowLayout Syntax: FlowLayout fl = new FlowLayout(); You tell an applet to use a particular LayoutManager instance by passing the object to the applet's setLayout() method like this: this.setLayout(fl); Or in one line: this.setLayout(new FlowLayout()); Most of the time setLayout() is called in the init() method.

Rina Example import java.awt.*; import java.applet.*; public class FLExample extends Applet{ public void init(){ this.setLayout(new FlowLayout()); this.add( new Button("First")); this.add( new Button("Second")); this.add( new Button("Third")); } }

Rina Alignment You can change the alignment of a FlowLayout in the constructor. Components are normally centered in an applet. You can make them left or right justified instead. To do this just pass one of the defined constants: –FlowLayout.LEFT, –FlowLayout.RIGHT –FlowLayout.CENTER Example: this.setLayout(new FlowLayout(FlowLayout.RIGHT));

Rina Example import java.awt.*; import java.applet.*; public class FLExampleLeft extends Applet{ public void init(){ this.setLayout(new FlowLayout(FlowLayout.LEFT)); this.add( new Button("First")); this.add( new Button("Second")); this.add( new Button("Third")); } }

Rina Separating components Most LayoutManagers allow you to control the minimum amount of vertical and horizontal space between different components. In FlowLayout you may pass the horizontal and vertical space as arguments (in pixels): FlowLayout(int alignment, int hgap, int vgap); Also you have : –setHgap(int); –setVgap(int );

Rina Hgap Example import java.awt.*; import java.applet.*; public class FLExampleLeft1 extends Applet{ public void init(){ FlowLayout fl=new FlowLayout(FlowLayout.LEFT); this.setLayout(fl); fl.setHgap(50); this.add( new Button("First")); this.add( new Button("Second")); this.add( new Button("Third")); } }

Rina BorderLayout A BorderLayout organizes an applet into 5 rectangular areas: –North, –South, –East, –West and –Center Each area is continually resized to fit the sizes of the components included in them. Center is whatever's left over in the middle.

Rina BorderLayout

Rina BorderLayout There's no centering, left alignment, or right alignment in a BorderLayout. You can add horizontal and vertical gaps between the areas. this.setLayout(new BorderLayout(5, 10)); To add components to a BorderLayout include the name of the section you wish to add them to like: this this.add("South", new Button("Start"));

Rina Example import java.applet.*; import java.awt.*; public class BLExample extends Applet { public void init() { this.setLayout(new BorderLayout(20, 10)); this.add("North", new Button("North")); this.add("South", new Button("South")); this.add("Center", new Button("Center")); this.add("East", new Button("East")); this.add("West", new Button("West")); } }

Rina GridLayout A GridLayout divides an applet into a specified number of rows and columns which form a grid of cells, each equally sized and spaced. As Components are added to the layout they are placed in the cells, starting at the upper left hand corner and moving to the right and down the page. Each component is sized to fit into its cell. This tends to squeeze and stretch components unnecessarily.

Rina Example import java.awt.*; import java.applet.Applet; public class GLExample extends Applet { public void init() { setLayout(new GridLayout(3,2)); add(new Button("1")); add(new Button("2")); add(new Button("3")); add(new Button("4")); add(new Button("5")); add(new Button("6")); }

Rina GridBagLayout GridBagLayout is the most precise of the five awt LayoutManagers. Each GridBagLayout uses a rectangular grid of cells, but each component can occupy one or more cells of the layout. It's similar to the GridLayout, but components do not need to be the same size. Furthermore components are not necessarily placed in the cells beginning at the upper left-hand corner and moving to the right and down.

Rina GridBagLayout The GridBagLayout constructor is trivial, GridBagLayout() with no arguments. GridBagLayout gbl = new GridBagLayout(); Unlike the GridLayout() constructor, this does not say how many rows or columns there will be. If you put a component in row 8 and column 2, then Java will make sure there are at least nine rows and three columns. (Rows and columns start counting at zero.)

Rina CardLayout A CardLayout breaks the applet into a deck of cards, each of which has its own LayoutManager. Only one card appears on the screen at a time. The user flips between cards, each of which shows a different set of components. In Java this might be used for a series of data input screens, where more input is needed than can comfortably be fit on one screen.

Rina Sun Example

Rina Sun Example

Rina Example import java.awt.*; public class Card extends java.applet.Applet { CardLayout cards = new CardLayout(); public void init() { setLayout( cards ); add("one", new Button("one") ); add("two", new Button("two") ); add("three", new Button("three") ); } public boolean action( Event e, Object arg){ cards.next( this); return true; } }

Rina Any Questions?