1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.

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

Introduction to Java 2 Programming
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
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
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng 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.
Graphical User Interface (GUI) Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
GUI and event-driven programming An introduction.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
Java Swing Chris North cs3724: HCI. AWT to Swing AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends.
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
Introduction to Java GUI Creating Graphical User Interfaces © copyright Bobby Hoggard / material may not be redistributed without permission.
Java Programming Chapter 10 Graphical User Interfaces.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
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.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
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.
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.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
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.
GUI development in Java L. Grewe Two methodologies for things to appear on the screen 1. By painting / drawing e.g. drawing an Image e.g. drawing an.
Field Trip #19 Animations with Java By Keith Lynn.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
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.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
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.
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.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 14 : Swing II King Fahd University of Petroleum & Minerals College of Computer Science.
Basics of GUI Programming Chapter 11 and Chapter 22.
1 Chapter 16: Creating Windows. 2 Basics of GUI Programming How to create a Window. TryWindow.java You always need a JFrame component before creating.
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 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Graphical User Interface (pronounced "gooey")
Tim McKenna Layout Mangers in Java Tim McKenna
Ellen Walker Hiram College
Chapter 13: Advanced GUIs and Graphics
תכנות מכוון עצמים בשפת JAVA
Tim McKenna Layout Mangers in Java Tim McKenna
Steps to Creating a GUI Interface
Week 8 Swing NetBeans GUI Builder
Advanced GUIs and Graphics
Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park

2 Creating GUIs Resources Appendix C of textbook Javadoc for the JDK Swing tutorial Course slides and code handouts Java Ranch

3 GUI (Graphical User Interface) You create GUIs by defining objects such as Text fields Labels Buttons Checkboxes Radioboxes Menus Tables Etc.

4 Java GUI Classes AWT (Abstract Window Toolkit) (java.awt.*) Old GUI framework for Java (Java 1.1) Some reliance on native code counterparts Platform independence problems Swing (javax.swing.*) New GUI framework first introduced in Java 1.2 Includes AWT features plus many enhancements Pure Java components (no reliance on native code) Pluggable look and feel architecture SWT (Standard Widget Toolkit; from Eclipse)

5 GUI Classes GUI classes can be organized in three groups Container classes – Hold other GUI Components JFrame - JPanel JApplet Component classes – (e.g., JButton, JTextfield, etc.) Helper classes – Describe properties of other GUI Componets Color Graphics Dimension Other

6 How to Create a GUI Define a Frame or Applet to hold the components. From now on we will use only frames. Add components to the frame Add actions to your GUI by adding listeners to GUI components

7 JFrame Hierarchy Several super classes and well as implemented interfaces Many, member methods including inherited methods that allow for operations such as resizing, setting properties, adding components, etc. Object Component Container Window Frame JFrame

8 JFrame Structure Most things go into content pane getContentPane() Use glassPane for pop up menus, some animations Methods getRootPane() getLayeredPane() getContentPane() getGlassPane() Can set…Pane explicitly glassPane rootPane JFrame layeredPane LayeredPane contains contentPane LayeredPane manages (optional) JMenuBar

9 Examples Examples in gui.jar For now our examples have no action associated with them. Let’s see example in ex1 package ex2 is basically ex1 but reduced to one class

10 Event Dispatching Thread (From Wikipedia) Background thread to process events from the AWT graphical interface event queue These events are mainly update events that Cause components to redraw themselves Represent input events Swing uses a single-threaded painting model where only the Event Dispatching thread is the only valid thread that can update user interface components Updating components from other threads is a source of common bugs

11 Event Dispatching Thread javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndDisplayGUI(); } }); Following code fragment allows the current thread to execute the GUI code in the dispatching thread. createAndDisplayGUI – method that actually defines the GUI

12 GUI Elements – Layout Definition Arrangement of widgets in container Layout specification Logical terms (2 nd row, 1 st column, left) Preferred approach Actual coordinates (100 pixels, 5 inches) Can be too rigid, limited to certain window sizes Layout manager Entity translating layout specifications into actual coordinates at runtime, depending on conditions

13 Java Layout Managers Flowlayout Lays out components from left to right GridLayout Lays out components in a grid of user specified size BorderLayout Designates portions of the container as North, South, East, West, and Center CardLayout Adds components one on top of another GridBagLayout Customizable manager that can use rows and columns of varying lengths

14 Example Example in gui.jar ex3 (when manager = LayoutManager.Grid) ex3 (when manager = LayoutManager.Flow)