Dept. of CSIE, National University of Tainan 10/21/2012 Arranging Components on a User Interface.

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

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.
Graphical User Interfaces
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
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.
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.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
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.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
GUI and event-driven programming An introduction.
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
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.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Introduction to Java Applet Programs Section 1.3Intro. to Java Applet Programs: a Greeter Applet Section 3.7Graphical/Internet Java: Applet: An Einstein.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
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.
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.
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.
Layout Manager Summary
© Marty Hall, Larry Brown, Web core programming 1 Layout Managers Arranging Elements in Windows.
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.
Layout Managers CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
University of Limerick1 Software Architecture Java Layout Managers.
Chapter 14 – Using Layout Managers and Events Dr. James Burns –
Introduction to Java Applet Programs Section 1.3Intro. to Java Applet Programs: a Greeter Applet Section 3.7Graphical/Internet Java: Applet: An Einstein.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
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.
J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.
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.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Java Layouts CSIS 3701: Advanced Object Oriented Programming.
Graphical User Interface (GUI)
Event Handler Methods Text field Object Responder JAVA AWT Environment: Messages are sent between JAVA Objects Screen Event Notification Press Button.
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 Working with Swing.
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.
Chapter 5 Patterns and GUI Programming -Part 2-. STRATEGY Pattern Layout Managers What if we need to specifies pixel position of components when  User.
Object-Orientated Analysis, Design and Programming
Graphical User Interfaces
Graphical User Interfaces -- GUIs
Swing JComponents.
GUIs Model/View/Controller Layouts
Modern Programming Language Java
Containers and Components
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
Panels & Layout Managers
Chapter 10 Getting Started with Graphics Programming
LayoutManagers The LayoutManagers are used to arrange components in a particular manner. LayoutManager is an interface that is implemented by all the classes.
GUI Layouts By: Leonard & Saif.
Presentation transcript:

Dept. of CSIE, National University of Tainan 10/21/2012 Arranging Components on a User Interface

Laying Out an Interface 2 A layout manager determines how components will be arranged when they are added to a container. layout managers: BorderLayout, BoxLayout, CardLayout, FlowLayout, GridBagLayout, and GridLayout. Example FlowLayout flo = new FlowLayout(); After you create a layout manager, you make it the layout manager for a container by using the container’s setLayout() method. If no layout manager is specified, its default layout will be used—FlowLayout for panels and BorderLayout for frames and windows.

Flow Layout 3 FlowLayout(int, int, int) constructor takes the following three arguments, in order:  The alignment, which must be one of five class variables of FlowLayout: CENTER, LEFT, RIGHT, LEADING, or TRAILING  The horizontal gap between components, in pixels  The vertical gap, in pixels FlowLayout righty = new FlowLayout(FlowLayout.RIGHT); FlowLayout flo = new FlowLayout(FlowLayout.CENTER, 30, 10);

Stacker.java 4 public class Stacker extends JFrame { public Stacker() { super(“Stacker”); setSize(430, 150); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create top panel JPanel commandPane = new JPanel(); BoxLayout horizontal = new BoxLayout(commandPane, BoxLayout.X_AXIS); commandPane.setLayout(horizontal);

Stacker.java 5 JButton subscribe = new JButton(“Subscribe”); JButton unsubscribe = new JButton(“Unsubscribe”); JButton refresh = new JButton(“Refresh”); JButton save = new JButton(“Save”); commandPane.add(subscribe); commandPane.add(unsubscribe); commandPane.add(refresh); commandPane.add(save); // create bottom panel JPanel textPane = new JPanel(); JTextArea text = new JTextArea(4, 70); JScrollPane scrollPane = new JScrollPane(text);

Stacker.java 6 // put them together FlowLayout flow = new FlowLayout(); setLayout(flow); add(commandPane); add(scrollPane); setVisible(true); } public static void main(String[] arguments) { Stacker st = new Stacker(); } }

7

Grid Layout 8 The grid layout manager arranges components into a grid of rows and columns. Components are added first to the top row of the grid, beginning with the leftmost grid cell and continuing to the right. GridLayout gr = new GridLayout(10, 3); GridLayout gr2 = new GridLayout(10, 3, 5, 8); //a grid layout with 10 rows and 3 columns, a horizontal gap of 5 //pixels, and a vertical gap of 8 pixels:

Bunch.java 9 public class Bunch extends JFrame { JButton marcia = new JButton(“Marcia”); JButton carol = new JButton(“Carol”); JButton greg = new JButton(“Greg”); JButton jan = new JButton(“Jan”); JButton alice = new JButton(“Alice”); JButton peter = new JButton(“Peter”); JButton cindy = new JButton(“Cindy”); JButton mike = new JButton(“Mike”); JButton bobby = new JButton(“Bobby”); public Bunch() { super(“Bunch”); setSize(260, 260); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Bunch.java 10 JPanel pane = new JPanel(); GridLayout family = new GridLayout(3, 3, 10, 10); pane.setLayout(family); pane.add(marcia); pane.add(carol); pane.add(greg); pane.add(jan); pane.add(alice); pane.add(peter); pane.add(cindy); pane.add(mike); pane.add(bobby); add(pane); setVisible(true); }

Bunch.java 11 public static void main(String[] arguments) { Bunch frame = new Bunch(); } }

Border Layout 12 Border.java public class Border extends JFrame { JButton nButton = new JButton(“North”); JButton sButton = new JButton(“South”); JButton eButton = new JButton(“East”); JButton wButton = new JButton(“West”); JButton cButton = new JButton(“Center”); public Border() { super(“Border”); setSize(240, 280); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout())

Border Layout 13 add(nButton, BorderLayout.NORTH); add(sButton, BorderLayout.SOUTH); add(eButton, BorderLayout.EAST); add(wButton, BorderLayout.WEST); add(cButton, BorderLayout.CENTER); } public static void main(String[] arguments) { Border frame = new Border(); frame.setVisible(true); } }

14