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.

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
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
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.
GUI programming AWT(Abstract Windows Toolkit)-GUI components library when Java was introduced AWT was replaced by Swing components import javax.swing.*;
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.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
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.
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 Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
MSc Workshop - © S. Kamin, U.Reddy Lect 5 – GUI Prog - 1 Lecture 5 – GUI Programming r Inner classes  this and super r Layout r Reading: m.
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
CSE 219 Computer Science III Graphical User Interface.
Java GUI building with the AWT. 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.
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.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Layout Managers Arranges and lays out the GUI components on a container.
Layout Manager Summary
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
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.
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.
“Swing” - Constructing GUIs JButton JTextField. Layout Managers CENTERWEST CENTER BORDERLAYOUT this.setLayout(new BorderLayout()); this.add(displayCanvas,
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7-3 ( Book Chapter 14) GUI and Event-Driven Programming.
1 CSE 331 Composite Layouts; Decorators slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
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 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.
Chapter 7 A First Look at GUI Applications Layout Managers.
Graphical User Interfaces
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.
Advanced GUI Programming
Modern Programming Language Java
University of Central Florida COP 3330 Object Oriented Programming
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Timer class and inner classes
Containers and Components
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
Panels & Layout Managers
GUI building with the AWT
Chapter 7-3 (Book Chapter 14)
GUI Layouts By: Leonard & Saif.
Presentation transcript:

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. CHINAEI

JPanels  The JPanel class provides general- purpose containers, known as panels.  These panels allow us to organize the components that make up our GUI; Each component will represent an important element of our GUI such as a button, label, etc.  JPanels can be given specific layouts to reflect how we want the GUI components to be organized.

JPanel(cont.)  To create a new JPanel, we need to use the default constructor.  To add a component to a panel, we invoke the add(Component comp) method on the panel. Keep in mind that you can only add objects of classes that extend/inherit from JComponent. You can easily look this up in the Java API. Note: The order in which you add Components can matter. It depends on the Layout you are working with.  Finally, to set the layout of a panel to a specifc layout manager, we invoke the setLayout(LayoutManager mgr) method on the panel. We can create a new object of the corresponding Layout class as a parameter.

Our Goal

GridLayout  A JPanel with a GridLayout manager places the components that are added to it in a grid of cells.  Each component takes all the available space within its cell, and each cell is exactly the same size.  Components are added starting at the first row until it is filled, then the second row, and so on.  Example:  JPanel grid = new JPanel();  grid.setLayout(new GridLayout(5, 4));  JButton rTCButton = new JButton(“Rtc”);  grid.add(rTCButton);  JButton cEButton = new JButton(“CE”);  grid.add(cEButton);

BoxLayout  A BoxLayout manager arranges components either on top of each other or in a row.  The way to state which orientation you would like the BoxLayout to have is by establishing a constant when you use its constructor. These constants are:  BoxLayout.Y_AXIS (stacks components on top of each other)  BoxLayout.X_AXIS (places components in a row)  Example:  JPanel box = new JPanel();  box.setLayout(box, BoxLayout.Y_AXIS);

BorderLayout  A JPanel with a set BorderLayout manager arranges and resizes its components to fit in five regions: north, south, east, west, and center.  Each region may contain only one component. However, that one component may have several components.  Just like the BoxLayout, the regions are identified by a corresponding constant:  BorderLayout.NORTH  BorderLayout.WEST  BorderLayout.CENTER  BorderLayout.SOUTH  BorderLayout.EAST

BorderLayout(cont.)  Example:  JPanel myPanel = new JPanel();  myPanel.setLayout(new BorderLayout());  JButton button = new Jbutton();  myPanel.add(button, BorderLayout.EAST); Unlike BoxLayout, you specify locations on the BorderLayout when you add a component.

Listeners Hints:  Use the methods added to the WindowMainPanel class to your convenience (setDisplayText(), getDisplayText(), setStatusBarText() and getStatusBarText().  Consider using substrings and String concatenation.  Look up the String class method substring(int beginIndex, int endIndex) in the Java API.  String concatenation is the operation of joining character strings end-to-end using the plus (+) operator.  For example, System.out.println(“Hello, “ + “world!”); prints “Hello, world!” to the console.