Creating Graphical User Interfaces

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
Graphical User Interfaces
Graphic User Interfaces Layout Managers Event Handling.
Corresponds with Chapter 12
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Inheritance Review CSC 171 FALL 2004 LECTURE 19. READING Read Horstmann, Chapter 11 Look at Chapter 12 – Will not be on MT or Final – One lab Begin Reading.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
LAB SESSION 10 *LAYOUT MANAGER *LISTENERS. Laying the components manually by using a null layout is tedious. Each container object has a layout manager.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.
GUI Layout Managers Arkadiusz Edward Komenda. Outline Components and Containers Layout Managers Flow Layout Grid Layout Border Layout Nested Containers.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
GUI and event-driven programming An introduction.
Java Programming Chapter 10 Graphical User Interfaces.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
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.
CSE 219 Computer Science III Graphical User Interface.
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.
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.
JFrame and JPanel CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
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.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
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.
Computer Science 209 GUIs Model/View/Controller Layouts.
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.
Graphical User Interfaces Tonga Institute of Higher Education.
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.
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.
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.
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.
SE-1020 Dr. Mark L. Hornick 1 Creating Graphical User Interfaces.
Chapter 7 A First Look at GUI Applications Layout Managers.
Graphical User Interfaces
Graphical User Interfaces -- GUIs
Christopher Budo, Davis Nygren, spencer franks, Luke miller
Layout Managers Layout Manager—an object that decides how components will be arranged in a container Some types of layout managers: BorderLayout FlowLayout.
Swing JComponents.
Modern Programming Language Java
Tim McKenna Layout Mangers in Java Tim McKenna
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Containers and Components
Tim McKenna Layout Mangers in Java Tim McKenna
Graphical User Interface
Chapter 7-3 (Book Chapter 14)
GUI building with the AWT
Layout Organization and Management
Graphical User Interface
Presentation transcript:

Creating Graphical User Interfaces Dr. Mark L. Hornick

Placing GUI components on a JFrame CS-1020 11/17/2018 Placing GUI components on a JFrame There are two ways to put GUI components on the content pane of a JFrame: Absolute positioning You explicitly specify the position and size of GUI objects within the content pane btnQuit.setBounds( 10, 125, 80, 30 ); Use a Layout Manager A class that controls automatic placement of components The content pane of a frame is where we can place GUI components. Among the approaches available to us to place components, we will study the easier one here. The easier absolute positioning is not a recommended approach for practical applications, but our objective here is to learn the basic handling of events and placement of GUI objects, we will use the easier approach. Chapter 12 of the textbook discusses different layout managers. SE-1020 Dr. Mark L. Hornick Dr. Mark L. Hornick

Layout Managers automatically determine how the GUI components appear within the container Many different layout managers exist; some are: FlowLayout BorderLayout GridLayout To use, set the layout manager of a JFrame’s Container to the type of layout manager you want to use: FlowLayout fl = new FlowLayout(FlowLayout.CENTER); contentPane.setLayout(fl); SE-1020 Dr. Mark L. Hornick

Using FlowLayout In using this layout, GUI components are placed in left-to-right order. When the component does not fit on the same line, left-to-right placement continues on the next line. As a default, components on each line are centered. SE-1020 Dr. Mark L. Hornick

FlowLayout behavior when the frame containing the components is resized SE-1020 Dr. Mark L. Hornick

BorderLayout This layout manager divides the container into five regions: center, north, south, east, and west. Not all regions have to be occupied. SE-1020 Dr. Mark L. Hornick

BorderLayout resizing CS-1020 11/17/2018 BorderLayout resizing The north and south regions expand or shrink in width only The east and west regions expand or shrink in height only The center region expands or shrinks on both height and width. contentPane.setLayout(new BorderLayout()); contentPane.add(button1, BorderLayout.NORTH); contentPane.add(button2, BorderLayout.SOUTH); contentPane.add(button3, BorderLayout.EAST); contentPane.add(button4, BorderLayout.WEST); contentPane.add(button5, BorderLayout.CENTER); SE-1020 Dr. Mark L. Hornick Dr. Mark L. Hornick

GridLayout Places GUI components on equal-size N by M grids. Components are placed in top-to-bottom, left-to-right order. Number of rows and columns remains the same after the frame is resized, but the width and height of each region will change. SE-1020 Dr. Mark L. Hornick

GridLayout resizing SE-1020 Dr. Mark L. Hornick

Complex layouts For sophisticated GUI’s, it can be difficult to use a single layout manager to get the look you are after. Another approach is to use panels Multiple panels can be placed in a content pane The class that implements a panel is JPanel Panel 1 Panel 3 Panel 3 SE-1020 Dr. Mark L. Hornick

Using Panels Panels can be placed on a JFrame using absolute positioning using a layout manager Each panel can employ it’s own layout manager or not UI components are added to the panels, rather than the JFrame But you can still add components to the JFrame as well Border Layout panel Absolute positioning panel Flow Layout panel SE-1020 Dr. Mark L. Hornick

Nested Layouts A panel can be placed inside another panel This is called nesting panels Nesting can be done to any level Here, the East region of the outer panel contains a border layout SE-1020 Dr. Mark L. Hornick

Another nested panel example Here, the Center region of the outer panel contains a border layout SE-1020 Dr. Mark L. Hornick

North Center South SE-1020 Dr. Mark L. Hornick

North Center South SE-1020 Dr. Mark L. Hornick