Graphical User Interface Components Chapter 14. 2 What You Will Learn Text Areas Text Areas Sliders Sliders Menus Menus –With frames –Pop up menus Look.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

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.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 17 Creating User Interfaces.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
 Pearson Education, Inc. All rights reserved GUI Components: Part 2.
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.
Advanced Java Class GUI – part 1. Intro to GUI GUI = Graphical User Interface -- “Gooey” Just because it’s “gooey” does not mean you may write messy code.
1 L48 Advanced GUI Component (3). 2 OBJECTIVES  To use additional layout managers.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
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.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
1 L47 Advanced GUI Component (2). 2 OBJECTIVES  To create and manipulate pop-up menus and windows.  To change the look-and-feel of a GUI, using Swing's.
1 L46 Advanced GUI Component (1). 2 OBJECTIVES  To create and manipulate sliders, and menus,
More on 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.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
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 Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
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.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
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.
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.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
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.
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.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
AGDER COLLEGEFACULTY OF ENGINEERING & SCIENCE GUI Components ikt403 – Object-Oriented Software Development.
CHAPTER:07 JAVA IDE PROGRAMMING-II Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise.
Review_6 AWT, Swing, ActionListener, and Graphics.
Creating User Interfaces Chapter 13 CSCI CSCI 1302 – Creating User Interfaces2 Outline Introduction Common Features of Swing GUI Components Buttons.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Developing GUIs With the Eclipse Visual Editor, Swing/AWT Edition David Gallardo.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
GUIs & Event-Driven Programming Chapter 11 Review.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Java GUI.
Provision for GUIs in Java
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
MSIS670: Object-Oriented Software Engineering
Event Driven Programming and Graphical User Interface
IFS410: Advanced Analysis and Design
Chapter 17 Creating User Interfaces
Chapter 17 Creating User Interfaces
Advanced GUIs and Graphics
Presentation transcript:

Graphical User Interface Components Chapter 14

2 What You Will Learn Text Areas Text Areas Sliders Sliders Menus Menus –With frames –Pop up menus Look and feel options Look and feel options

3 JTextArea Area for manipulating multiple lines of text Area for manipulating multiple lines of text Extends JTextComponent Extends JTextComponent –Inherits from that class View Figure 14.1 View Figure 14.1Figure 14.1Figure 14.1 Note Note –Creation of box –Creation of two JTextArea objects –Copy of marked text to other text area

4 Subclass of JPanel A JPanel can A JPanel can –Aggregate a set of GUI components –Create dedicated drawing areas –Create areas that receive mouse events Subclass of a JPanel should Subclass of a JPanel should –Override method paintComponent –Call the superclass version as first statement Note the customized JPanel subclass, Figure 14.2 Note the customized JPanel subclass, Figure 14.2 Figure 14.2 Figure 14.2

5 Demonstration of Customized JPanel Now view Figure 14.3 Now view Figure 14.3Figure 14.3Figure 14.3 Note Note –Declaration, instantiation of the CustomPanel –Method draw used in actionPerformed methods

6 Another Customized JPanel Class Possible for the (sub)class to handle its own events Possible for the (sub)class to handle its own events Note SelfContainedPanel class, Figure 14.4 Note SelfContainedPanel class, Figure 14.4SelfContainedPanel This class has This class has –Mouse activity handlers –Preferred dimension specified –Call to paintComponent method Figure 14.5 uses this customized subclass Figure 14.5 uses this customized subclass Figure 14.5 Figure 14.5

7 JSlider s Enable users to select from range of integer values Enable users to select from range of integer values Features Features –Tick marks (major and minor) –Snap-to ticks –Orientation (horizontal and vertical) thumb tick mark

8 JSlider s JPanel subclass for drawing circles, Figure 14.7 JPanel subclass for drawing circles, Figure 14.7 Figure 14.7 Figure 14.7 JSlider used to control size of a circle graphic, Figure 14.8 JSlider used to control size of a circle graphic, Figure 14.8Figure 14.8Figure 14.8 Note Note –Slider declaration, implementation –Registration of listener for the slider

9 Using Menus with Frames Allows for performing actions with cluttering GUI Allows for performing actions with cluttering GUI Contained by menu bar – JMenuBar Contained by menu bar – JMenuBar Comprised of menu items – MenuItem Comprised of menu items – MenuItem Note Figure 14.9 Note Figure 14.9Figure 14.9Figure 14.9 –Declares menu items –Populates the menus –Specifies actions for menu choices

10 JPopupMenu Menus that are context-sensitive Menus that are context-sensitive –Right click and popup menu appears In Swing, use JPopupMenu In Swing, use JPopupMenu –Provide options specific to component –Popup trigger event occurs when object right mouse clicked Demonstration of JPopupMenu shown in Figure Demonstration of JPopupMenu shown in Figure Figure Figure 14.10

11 Pluggable Look-and-Feel Recall that Java is designed to run on variety of platforms Recall that Java is designed to run on variety of platforms –GUI components on a Mac, look different from those on a PC or on a UNIX platform Look-and-Feel capability Look-and-Feel capability –Java program on a particular platform looks like other programs on the same platform –Also possible to specify the look-and-feel of a Swing GUI

12 Pluggable Look-and-Feel Figure demonstrates how to change the appearance Figure demonstrates how to change the appearance Figure Figure Note use of UIManager methods Note use of UIManager methods

13 JDesktopPane and JInternalFrame Multiple document interface Multiple document interface –Main (parent) window –Child windows View Figure which demonstrates this View Figure which demonstrates thisFigure Figure Note Note –Declaration, instantiation of JDesktopPane object –Choosing and painting of the icons

14 JTabbedPane Arranges GUI components into layers Arranges GUI components into layers –One layer visible at a time –Access each layer via a tab View tab demo program, Figure View tab demo program, Figure Figure Figure Note Note –declaration of tabbed panes

15 Layout Managers BoxLayout a rranges GUI components BoxLayout a rranges GUI components –Horizontally along x-axis –Vertically along y-axis

16 BoxLayout Demonstrated in Figure Demonstrated in Figure 14.15Figure 14.15Figure –Also uses the tabs –Offers several different options for laying out three JButton s Note Note –Creation of boxes –Adding of buttons

17 GridBagLayout Layout Manager Flexible GridBagLayout Flexible GridBagLayout –Components can vary in size –Components can occupy multiple rows and columns –Components can be added in any order Uses GridBagConstraints Uses GridBagConstraints –Specifies how component is placed in GridBagLayout

18 GridBagLayout Layout Manager GridBagConstraints fields GridBagConstraints fields

19 GridBagLayout Layout Manager Designing a GUI to use the GridBagLayout Designing a GUI to use the GridBagLayout Program for this layout demonstrated in Figure Program for this layout demonstrated in Figure Figure Figure Row Column

20 GridBagLayout Layout Manager Variation of GridBagLayout does not use gridx and gridy Variation of GridBagLayout does not use gridx and gridy –Use constants RELATIVE and REMAINDER RELATIVE RELATIVE –Specifies next-to-last component placement in row or column –Component placed next to one previously added REMAINDER REMAINDER –Specifies component as last component in row or column

21 GridBagLayout Layout Manager Use of constraints demonstrated in Figure Use of constraints demonstrated in Figure Figure Figure Note Note –Setting constraint weights –Setting grid width –Adding buttons –The addComponent method