Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Introduction to Swing Components Chapter 14. Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program.
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
Introduction to JFC Swing Written by Adam Carmi. Agenda About JFC and Swing Pluggable Look and Feel Swing Components Borders Layout Management Events.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
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.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Java Programming Chapter 10 Graphical User Interfaces.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
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.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Introduction to Swing Components Chapter 14.  Part of the Java Foundation Classes (JFC)  Provides a rich set of GUI components  Used to create a Java.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
Field Trip #19 Animations with Java By Keith Lynn.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
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.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
CIS 068 Welcome to CIS 068 ! Lesson 7: 1.GUIs: JAVA Swing 2.Streams and Files.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
Layout Manager Summary
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
University of Limerick1 Software Architecture Java Layout Managers.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Swing Components. Introduction Swing – A set of GUI classes – Part of the Java's standard library –Much better than the previous library: AWT Abstract.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Basics of GUI Programming Chapter 11 and Chapter 22.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Module 13: Swing API Object Oriented Programming(Java)
University of Central Florida COP 3330 Object Oriented Programming
Graphical User Interface (pronounced "gooey")
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Welcome to CIS 068 ! GUIs: JAVA Swing
Tim McKenna Layout Mangers in Java Tim McKenna
Steps to Creating a GUI Interface
Advanced GUIs and Graphics
Graphical User Interface
Presentation transcript:

Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila

 Example:  The First Swing Program

Container: JFrame Layout: BorderLayout North Center Components: JLabel JButton, containing an ImageIcon

1. import package 2. set up top level container (e.g. JFrame) 3. apply layout (e.g. BorderLayout) 4. add components (e.g. Label, Button) 5. REGISTER listeners 6. show it to the world !

CIS import package 2. set up top level container (e.g. JFrame) 3. apply layout (e.g. BorderLayout) 4. add components (e.g. Label, Button) 5. REGISTER listeners 6. show it to the world !

Top Level Containers General Purpose Containers Special Purpose Containers Basic Controls Uneditable Information Displays Interactive Displays of Highly Formatted Information

Top Level Containers Your application usually extends one of these classes !

 Every program with a Swing GUI must contain at least one top-level Swing container.  A top-level Swing container provides the support that Swing components need to perform their painting and event handling.  There are three top-level Swing containers: JFrame, JDialog, and (for applets) JApplet. ◦ Each JFrame object implements a single main window, and each JDialog implements a secondary window (a window that's dependent on another window). ◦ Each JApplet object implements an applet's display area within a browser window.

JDialog Jframe JDialog

 General Purpose Containers

typically used to collect Basic Controls (JButton, JChoiceBox…) Added to layout of top-level containers JPanel JFrame

 Special Purpose Containers

The glass pane Hidden, by default. If you make the glass pane visible, then it's like a sheet of glass over all the other parts of the root pane. The layered pane Serves to position its contents, which consist of the content pane and the optional menu bar. Can also hold other components in a specified Z order. The content pane The container of the root pane's visible components, excluding the menu bar. The optional menu bar The home for the root pane's container's menus. If the container has a menu bar, you generally use the container's setMenuBar or setJMenuBar method to put the menu bar in the appropriate place.

 Basic Controls

Unlike ‘passive’ containers, controls are the ‘active’ part of your GUI  Remark: containers aren’t only ‘passive’, they are also ‘active’ sources of events, eg. Mouse-events. Being the visible part of your interface, controls bring your application to life Controls are event sources ! Objects of your application register to controls to handle the events

 Uneditable Information Displays

 Interactive Displays of Highly Formatted Information

 How to glue it all together:  The Layout Management

The process of determining the size and position of components A layout manager is an object that performs layout management for the components within the container. Layout managers have the final say on the size and position of components added to a container Using the add method to put a component in a container, you must ALWAYS take the container's layout manager into account

 Java supplies five commonly used layout managers: 1.BorderLayout 2.BoxLayout 3.FlowLayout 4.GridBagLayout 5.GridLayout

BorderLayout Position must be specified, e.g. add (“North”, myComponent)

BoxLayout The BoxLayout class puts components in a single row or column.

FlowLayout FlowLayout is the default layout manager for every JPanel. It simply lays out components from left to right, starting new rows if necessary

GridBagLayout GridBagLayout is the most sophisticated, flexible layout manager the Java platform provides.

GridLayout GridLayout simply makes a bunch of components equal in size and displays them in the requested number of rows and columns.

 Examples: Using a JButton Using a JSlider Using a JCheckBox

 Some Constructors: JButton() Creates a button with no text or icon JButton(Icon icon) Creates a button with an icon JButton(String text) Creates a button with text JButton(String text, Icon icon) Creates a button with initial text and an icon

 Some Methods: addActionListener( ActionListener a) Registers ActionListener to JButton Inherited from AbstractButton setFont(Font font)Specifies Font (Type, Style, Size) Inherited from JComponent setBackground( Color color) Sets background color Inherited from JComponent setActionCommand (String text) Used to specify button if listener is registered to multiple buttons (see ActionEvent.getActionCommand())

 Some Constructors: JSlider() Creates a horizontal slider with the range 0 to 100 and an initial value of 50 JSlider( int min, int max, int value ) Creates a horizontal slider using the specified min, max and value. JSlider( Int orientation int min, int max, int value ) Creates a slider with the specified orientation and the specified minimum, maximum, and initial values.

 Some Methods: addChangeListener (ChangeListener cl) Registers ChangeListener to slider int getValue()Returns the slider’s value setValue(int value)Sets the slider’s value

 Some Constructors: JCheckBox()Creates an initially unselected check box button with no text, no icon. JCheckBox( String text) Creates an initially unselected check box with text. JCheckBox( String text, Icon icon, boolean selecte d) Creates a check box with text and icon, and specifies whether or not it is initially selected.

 Some Methods: addItemListener (ItemListener il) Registers ItemListener to checkbox Inherited from AbstractButton setSelected( boolean select) Sets the state of checkbox Inherited from AbstractButton boolean getSeleted () Gets the state of checkbox. calling method often saves from registering to the checkbox !

 Every top-level container indirectly contains an intermediate container known as a content pane.  the content pane contains, directly or indirectly, all of the visible components in the window's GUI.  The big exception to the rule is that if the top- level container has a menu bar, then by convention the menu bar goes in a special place outside of the content pane.

 Here is the code that adds the button and label to the panel, and the panel to the content pane

Questions? 36 Question in my mind is ? Should I ask this ? hmmmmmmmmm? Sorry I was sleeping sir !

If you have any query please feel free to ask Phone: Fax: University Of Engineering & Technology Taxila Pakistan