University of Central Florida COP 3330 Object Oriented Programming

Slides:



Advertisements
Similar presentations
Components and Containers
Advertisements

Introduction to Java 2 Programming
14 Copyright © 2005, Oracle. All rights reserved. User Interface Design: Swing Basics Planning the Application Layout.
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.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
THE SWING UI TOOLKIT Mostly from “The Swing Connection”The Swing Connection.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
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.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
Creating GUIs in Java using Swing David Meredith Aalborg University.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
CS3 - AWT/Swing1 The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness –The Abstract.
GUI Programming in Java
Introduction to Java GUI Creating Graphical User Interfaces © copyright Bobby Hoggard / material may not be redistributed without permission.
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.
Creating GUIs in Java using Swing Medialogy, Semester 7, 2010 Aalborg University, Aalborg David Meredith.
JAPPLET.
DAT602 Database Application Development Lecture 6 JAVA Swing.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
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.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
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.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
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.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
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.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
CSCI Swing1 The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness –The Abstract.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
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.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
Module 13: Swing API Object Oriented Programming(Java)
Provision for GUIs in Java
A First Look at GUI Applications
Provision for GUIs in Java
University of Central Florida COP 3330 Object Oriented Programming
Swing & the JFC – Advanced Java GUI
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Building Graphical User Interface with Swing a short introduction
Steps to Creating a GUI Interface
Advanced GUIs and Graphics
Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

University of Central Florida COP 3330 Object Oriented Programming

Graphical User Interface

Java Foundation Classes JFC a group of features to develop GUIs and adding graphics functionality and interactivity Contains features Swing GUI Components Pluggable Look-and-Feel Support Accessibility API Java 2D API Internationalization

Java Foundation Classes Most of the code in this trail uses only one or two Swing packages: javax.swing javax.swing.event (not always required) Java Foundation Classes Swing API has 18 public packages Commonly use only one or two Swing packages, javax.swing and javax.swing.event (not always required) javax.accessibility javax.swing.plaf javax.swing.text javax.swing javax.swing.plaf.basic javax.swing.text.html javax.swing.border javax.swing.plaf.metal javax.swing.text.html.parser javax.swing.colorchooser javax.swing.plaf.multi javax.swing.text.rtf javax.swing.event javax.swing.plaf.synth javax.swing.tree javax.swing.filechooser javax.swing.table javax.swing.undo

Top Level Containers Swing provides three top-level container classes JFrame  JDialog JApplet To display during runtime, every UI component must be part of a containment hierarchy, a tree of components that has a top-level container as its root Each UI component can be contained ONLY once If a component is already in a container and is then added to another container, the component will be removed from the first container and then added to the second

Top Level Containers Each top-level container has a content pane that contains the visible components in that top-level container's UI Optionally add a menu bar to a top-level container The menu bar convention is positioned within the top-level container, but outside the content pane Some look and feels, such as the Mac OS look and feel, gives the option of placing the menu bar in another place more appropriate for the look and feel, such as at the top of the screen

Top Level Containers

Top Level Containers A program that use Swing components have at least one top-level container as the root of a containment hierarchy As a rule, a standalone application with a Swing-based UI has at least one containment hierarchy with a JFrame as its root An application has one main window and two dialogs, therefore the application has three containment hierarchies, (i.e. three top-level containers) One containment hierarchy has a JFrame as its root and each of the other two has a JDialog object as its root A Swing-based applet has at least one containment hierarchy, exactly one of which is rooted by a JApplet object An applet that brings up a dialog has two containment hierarchies. The components in the browser window are in a containment hierarchy rooted by a JApplet object The dialog has a containment hierarchy rooted by a JDialog object

Adding Components Referencing the content pane JFrame frame = new JFrame(); Label label = new Label(); frame.getContentPane().add(label); The default content pane inherits from JComponent and uses BorderLayout as its layout manager However, getContentPane() method returns a Container object not JComponent object In order to use the content pane's JComponent features, it has to be typecast or create your own component to be the content pane

Adding Components Setting the content pane using JPanel JPanel layout manager by default is FlowLayout use the top-level container's setContentPane method Example //Create a panel and add components to it. JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setBorder(someBorder); contentPane.add(someComponent, BorderLayout.CENTER); contentPane.add(anotherComponent, BorderLayout.PAGE_END); topLevelContainer.setContentPane(contentPane);

Adding Menubar All top-level containers can hold a menu bar In practice, menu bars usually appear only in frames and applets Add a menu bar to a top-level container Create a JMenuBar object Populate it with menus Call setJMenuBar Example JFrame frame = new JFrame(); JMenuBar greenMenuBar = new JMenuBar(); frame.setJMenuBar(greenMenuBar);

Root Pane Each top-level container relies on a reclusive intermediate container called the root pane Root pane manages the content pane and the menu bar in addition to a couple of other containers Usually don’t be concerned with root pane but if need to intercept mouse clicks or paint over multiple components

Root Pane The glass pane The layered pane The content pane Hidden, by default, if made visible it's like a sheet of glass over all the other parts of the root pane Completely transparent unless you implement the glass pane's paintComponent method so that it does something, and it can intercept input events for the root pane The layered pane Serves to position its contents, the content pane and the optional menu bar. Can hold other components in a specified Z order. For information The content pane The container of the root pane's visible components, excluding the menu 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 setJMenuBar method to put the menu bar in the appropriate place