Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor 1947 - William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.

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

GUI. Swing Programs Four basic types of Top Level Window – JFrame, a top level window decorated like a native window – JWindow, an undecorated stand-alone.
Graphical User Interfaces
Graphical User Interfaces Java’s AWT and Swing APIs.
Graphical User Interfaces (Part IV)
Java Software Development Paradigm Lecture # 12. Basics of GUI.
CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
JAVA 程式語言入門 (II).  版面配置  事件驅動  Ch14_01.java 1. import javax.swing.*; 2. import java.awt.*; 3. class Ch14_01 4. { 5. public static void main(String.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
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.
LAB SESSION 10 *LAYOUT MANAGER *LISTENERS. Laying the components manually by using a null layout is tedious. Each container object has a layout manager.
Applets & Applications CSC 171 FALL 2001 LECTURE 15.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
Java Programming Chapter 10 Graphical User Interfaces.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Introduction to Computation and Problem Solving Class 15: Constructing Interfaces with Swing Prof. Steven R. Lerman and Dr. V. Judson Harward 1.
CSE 219 Computer Science III Graphical User Interface.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
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.
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.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
JFrame and JPanel CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
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.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
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.
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.
Computer Science 209 GUIs Model/View/Controller Layouts.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 14 : Swing II King Fahd University of Petroleum & Minerals College of Computer Science.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
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.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
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.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
1 Chapter 13 – More GUI Components Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides users with basic.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Dept. of CSIE, National University of Tainan 10/21/2012 Arranging Components on a User Interface.
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.
Modular Event Handling
GUIs and Events Rick Mercer.
Object-Orientated Analysis, Design and Programming
Graphical User Interfaces
Graphical User Interfaces -- GUIs
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.
GUIs Model/View/Controller Layouts
Modern Programming Language Java
Java GUI.
CHAPTER 7 & 8 REVIEW QUESTIONS
Applets & Applications
MSIS670: Object-Oriented Software Engineering
Creating Graphical User Interfaces
Graphical User Interface
Presentation transcript:

Layout Mangers CSC 171 FALL 2001 LECTURE 14

History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance device, later to be known as the transistor that will revolutionize the computer and give it the reliability that could not achieved with vacuum tubes.

Layout Mangers Java supports several predefined ways to control and manage layout Several

FLOW LAYOUT Like a typewriter – Starts upper left – Moves right – Moves down

JFrame Application public class FlowLayoutDemo extends JFrame { public static void main( String args[] ){ FlowLayoutDemo application = new FlowLayoutDemo(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } …..

Instance Variables private JButton leftButton, centerButton, rightButton; private Container container; private FlowLayout layout;

Constructor public FlowLayoutDemo() { super( "FlowLayout Demo" ); layout = new FlowLayout(); container = getContentPane(); container.setLayout( layout );

Buttons – inner class listener leftButton = new JButton( "Left" ); leftButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent event ) { layout.setAlignment( FlowLayout.LEFT ); layout.layoutContainer( container ); } } // end anonymous inner class ); // end call to addActionListener container.add( leftButton ); // add it

Visibility Controls setSize( 300, 75 ); setVisible( true );

BOARDER LAYOUT Based on a “NORTH, SOUTH, EAST, WEST, CENTER” concept. Elements added to specific regions

BorderLayout layout = new BorderLayout( 5, 5 ); // get content pane and set its layout Container container = getContentPane(); container.setLayout( layout );

Placing Buttons // place buttons in BorderLayout; order not important container.add( buttons[ 0 ], BorderLayout.NORTH ); container.add( buttons[ 1 ], BorderLayout.SOUTH ); container.add( buttons[ 2 ], BorderLayout.EAST ); container.add( buttons[ 3 ], BorderLayout.WEST ); container.add( buttons[ 4 ], BorderLayout.CENTER );

Listener as Interface public class BorderLayoutDemo extends JFrame implements ActionListener { public void actionPerformed( ActionEvent event ) { for ( int count = 0; count < buttons.length; count++ ) if ( event.getSource() == buttons[ count ] ) buttons[ count ].setVisible( false ); else buttons[ count ].setVisible( true ); layout.layoutContainer( getContentPane() ); }

GRID LAYOUT Like a table Elements adder in row major order

Gridlayout grid1 = new GridLayout( 2, 3, 5, 5 );// 2x3 grid2 = new GridLayout( 3, 2 ); // 3x2 // Items added in order

Switching Layouts public void actionPerformed( ActionEvent event ) { if ( toggle ) container.setLayout( grid2 ); else container.setLayout( grid1 ); toggle = !toggle; // set toggle to opposite value container.validate(); }

Panels Using panels we can use different layout managers for different regions of the screen

Set up Panels // set up panel and set its layout bPanel2 = new JPanel(); bPanel2.setLayout( new BorderLayout( 10, 5) ); // set up panel and set its layout buttonPanel = new JPanel(); buttonPanel.setLayout( new GridLayout( 1, buttons.length ) );

Add Panels to frame Container container = getContentPane(); container.add(buttonPanel,BorderLayout.SOUTH); container.add( bPanel2, BorderLayout.CENTER); THINK: containment structure panels within panels within panels....