Layout Managers Layout Manager—an object that decides how components will be arranged in a container Some types of layout managers: BorderLayout FlowLayout.

Slides:



Advertisements
Similar presentations
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
Corresponds with Chapter 12
1 Chapter 12 l Event-Driven Programming and GUIs l Swing Basics and a Simple Demo Program l Layout Managers l Buttons and Action Listeners l Container.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
More Advanced AWT Last week, you learned about Applets, Lists, and Buttons AWT provides several other “widgets” and tools: –Labels –Choice boxes –Check.
Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Gui Interfaces a la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington.
Events ● Anything that happens in a GUI is an event. For example: – User clicks a button, presses return when typing text, or chooses a menu item ( ActionEvent.
LAB SESSION 10 *LAYOUT MANAGER *LISTENERS. Laying the components manually by using a null layout is tedious. Each container object has a layout manager.
Event Handling n Events: an event is an object that describes a state change in a source. n Event Sources: A source is an object that generates an event.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
Chapter 121 Window Interfaces Using Swing Chapter 12.
1 UFCE3T-15-M Object- oriented Design and Programming Block 3 GUI Programming Jin Sa.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
Graphical User Interfaces (GUI) Abstract Windows Toolkit (AWT): java.awt GUI elements: Primitive Button, Label, Checkbox, Scrollbar, etc. Container Panel,
Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Graphical User Interface Components: Part 1 Chapter 11.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Layout Managers Arranges and lays out the GUI components on a container.
Layout Manager Summary
CS GUI Frameworks CS 3331 Fall CS 3331 Outline MVC Model GUI components (widgets) Layout managers Handling events.
Pravin Yannawar, DOCS, NMU Jalgaon. Basic Java : Event handling in AWT and Swing 2 Objectives of This Session Explain the Event handling mechanism & demonstrate.
Computer Science [3] Java Programming II - Laboratory Course Lab 4: Common GUI Event Types and Listener Interfaces Layout Mangers Faculty of Engineering.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Event Handling. 2 GUIs are event driven –Generate events when user interacts with GUI e.g., moving mouse, pressing button, typing in text field, etc.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 12 l Event-Driven Programming and GUIs l Swing Basics and.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
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.
Java layout managers. import java.awt.*; import java.awt.event.*; import javax.swing.*; class ButtonPanel extends JPanel implements ActionListener { public.
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.
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7-3 ( Book Chapter 14) GUI and Event-Driven Programming.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 Lecture 8: User Interface Components with Swing.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Chapter 7 A First Look at GUI Applications Layout Managers.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Chapter 14 Event-Driven Programming
Object-Orientated Analysis, Design and Programming
Chapter 12 Event-Driven Programming
Modern Programming Language Java
CSE 114 – Computer Science I Event Programming
Ellen Walker Hiram College
Event-driven programming for GUI
Creating Graphical User Interfaces
GUI building with the AWT
Graphical User Interface
Chapter 7-3 (Book Chapter 14)
Window Interfaces Using Swing Objects Chapter 12
Chapter 10 Getting Started with Graphics Programming
Window Interfaces Using Swing Objects Chapter 12
Chapter-2 Java Programming COMP-417
GUI building with the AWT
Graphical User Interface
Presentation transcript:

Layout Managers Layout Manager—an object that decides how components will be arranged in a container Some types of layout managers: BorderLayout FlowLayout GridLayout LAYOUT MANAGERS: Arranges the items you add according to certain rules. Different layout managers follow different rules, so you can have a good deal of control over how things are arranged in a windowing interface. DEFAULT LAYOUT MANAGERS: If you do not add a layout manager, then a default layout manager will be provided for you. BorderLayout If you specify that you want to add an object to the window and you do not specify where you want the object to be place, the object would be added to the CENTER.

The Border Layout Manager Five regions that can each have one component added to them: BorderLayout.NORTH BorderLayout.SOUTH BorderLayout.CENTER BorderLayout. WEST EAST contentPane.setLayout(new BorderLayout()); . . . contentPane.add(label1, BorderLayout.NORTH); contentPane is the name of the Container object that you would have created further up in this program. The CENTER region grows the most when the container grows and shrinks the most when the container shrinks

Example of BorderLayout setTitle("Layout Demonstration"); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); JLabel label1 = new JLabel("First label here"); contentPane.add(label1, BorderLayout.NORTH); JLabel label2 = new JLabel("Second label here"); contentPane.add(label2, BorderLayout.SOUTH); JLabel label3 = new JLabel("Third label here"); contentPane.add(label3, BorderLayout.CENTER); JLabel label4 = new JLabel("4TH label here"); contentPane.add(label4, BorderLayout.WEST);

The Flow Layout Manager The simplest layout manager Displays components from left to right in the order they are added to the container add method has one parameter which is the component to add Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); JLabel label1 = new JLabel(“First label here”); contentPane.add(label1); JLabel label2 = new JLabel(“Second label there”); contentPane.add(label2); FLOW LAYOUT: Simplest layout manager. The objects are arranged one after the other going from left to right

Example of FlowLayout setTitle("Layout Demonstration"); Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); JLabel label1 = new JLabel("First label here"); contentPane.add(label1); JLabel label2 = new JLabel("Second label here"); contentPane.add(label2); JLabel label3 = new JLabel("Third label here"); contentPane.add(label3); JLabel label4 = new JLabel("4TH label here"); contentPane.add(label4);

The Grid Layout Manager Specify a number of rows and columns All regions in the grid are equal size When the container changes size, each region grows or shrinks by the same amount contentPane.setLayout(new GridLayout(2, 3)); . . . contentPane.add(label1); contentPane.add(label2); Creates a grid layout with two rows and three columns. Rows are filled before columns.

Example of GridLayout contentPane.setLayout(new GridLayout(2,2)); JLabel label1 = new JLabel("First label here"); contentPane.add(label1); JLabel label2 = new JLabel("Second label here"); contentPane.add(label2); JLabel label3 = new JLabel("Third label here"); contentPane.add(label3); JLabel label4 = new JLabel("4TH label here"); contentPane.add(label4);

EVENTS, LISTENERS & LISTENER METHODS Event Class Listener Interface Listener Methods (Handlers) ActionEvent ActionListener actionPerformed (ActionEvent e) ItemEvent ItemListener itemStateChanged(ItemEvent e) WindowEvent WindowListener windowClosing(WindowEvent e) windowOpened(WindowEvent e) windowIconified(WindowEvent e) windowDeiconified(WindowEvent e) windowActivated(WindowEvent e) windowDeactivated(WindowEvent e) ContainerEvent ContainerListener componentAdded(ContainerEvent e) componentRemoved(ContainerEvent e)

Listener Methods (Handlers) Event Class Listener Interface Listener Methods (Handlers) ComponentEvent FocusEvent TextEvent KeyEvent MouseEvent AdjustmentEvent