14 Copyright © 2005, Oracle. All rights reserved. User Interface Design: Swing Basics Planning the Application Layout.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to XHTML Programming the World Wide Web Fourth edition.
AP STUDY SESSION 2.
1
Introduction to Java 2 Programming
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 Created by Cheryl M. Hughes The Web Wizards Guide to XML by Cheryl M. Hughes.
© 2014 by McGraw-Hill Education. This is proprietary material solely for authorized instructor use. Not authorized for sale or distribution in any manner.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module D (Office 2007 Version) Decision Analysis.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
15 Copyright © 2005, Oracle. All rights reserved. Adding User Interface Components and Event Handling.
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Microsoft Access 2007 Advanced Level. © Cheltenham Courseware Pty. Ltd. Slide No 2 Forms Customisation.
Local Customization Chapter 2. Local Customization 2-2 Objectives Customization Considerations Types of Data Elements Location for Locally Defined Data.
Process a Customer Chapter 2. Process a Customer 2-2 Objectives Understand what defines a Customer Learn how to check for an existing Customer Learn how.
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
Custom Services and Training Provider Details Chapter 4.
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Windows XP Project An Introduction to Microsoft Windows XP and Office 2003.
Creating a Dreamweaver Web Page and Local Site
Break Time Remaining 10:00.
ETS4 - What's new? - How to start? - Any questions?
© Telcordia Technologies 2004 – All Rights Reserved AETG Web Service Advanced Features AETG is a service mark of Telcordia Technologies. Telcordia Technologies.
PP Test Review Sections 6-1 to 6-6
Bright Futures Guidelines Priorities and Screening Tables
Vanderbilt Business Objects Users Group 1 Reporting Techniques & Formatting Beginning & Advanced.
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
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.
INTRODUCTION Lesson 1 – Microsoft Word Word Basics
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Office 2003 Integration Integrating Office 2003 Applications and the World Wide Web.
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
Benchmark Series Microsoft Excel 2013 Level 2
Sample Service Screenshots Enterprise Cloud Service 11.3.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
 Copyright I/O International, 2013 Visit us at: A Feature Within from Item Class User Friendly Maintenance  Copyright.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
Adding Up In Chunks.
INTRODUCTORY MICROSOFT WORD Lesson 7 – Working With Documents
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
Benchmark Series Microsoft Excel 2010 Level 1
Analyzing Genes and Genomes
Essential Cell Biology
PSSA Preparation.
Chapter 11 Creating Framed Layouts Principles of Web Design, 4 th Edition.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Chapter 13 Web Page Design Studio
Energy Generation in Mitochondria and Chlorplasts
South Dakota Library Network MetaLib User Interface South Dakota Library Network 1200 University, Unit 9672 Spearfish, SD © South Dakota.
Android Using Menus Yuliana Setiowati Rizky Yuniar Hakkun Ahmad Syauqi Ahsan 1Politeknik Elektronika Negeri Surabaya.
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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,
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.
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.
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 9: Graphical User Interfaces
Presentation transcript:

14 Copyright © 2005, Oracle. All rights reserved. User Interface Design: Swing Basics Planning the Application Layout

14-2 Copyright © 2005, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Explain Abstract Window Toolkit (AWT), Swing, and Java Foundation Classes (JFC) Detail the Swing UI containment hierarchy Describe how to use layout managers Add UI containers to an application to group components Embed UI components into UI containers Use the Swing pluggable look and feel

14-3 Copyright © 2005, Oracle. All rights reserved. Running Java UI Applications

14-4 Copyright © 2005, Oracle. All rights reserved. AWT, Swing, and JFC AWT, or Abstract Window Toolkit ( java.awt ): –A graphical user interface library –The predecessor to Swing components and the foundation for Swing and JFC Swing ( javax.swing ): –A more powerful graphical user interface library –Built on top of the AWT class hierarchy Java Foundation Classes (JFC): –A collection of APIs including: AWT, Swing, Accessibility API, Pluggable Look and Feel –Java 2D API, Drag and Drop support (since JDK 1.2)

14-5 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-6 Copyright © 2005, Oracle. All rights reserved. JButtonJSliderJTree JComboBoxJTextFieldJProgressBar InventoryItem Swing Features A set of visual components that have been available since JDK 1.1, but part of core JDK since version 1.2: Lightweight components compared to AWT Pluggable look and feel API Many more components than AWT

14-7 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-8 Copyright © 2005, Oracle. All rights reserved. Lightweight or Heavyweight Components? Heavyweight components Strong dependency on native peer code Each rendered in its own opaque window Early AWT components were mostly heavyweight Include some Swing top-level components ( JFrame, JApplet, JDialog ) Lightweight components No dependence on native peer code Can have transparent backgrounds Most Swing components are lightweight When displayed, they can appear nonrectangular Must be displayed in heavyweight container

14-9 Copyright © 2005, Oracle. All rights reserved. Planning the UI Layout Building a UI application involves planning, even more so when building Swing applications. Planning requires understanding the following concepts and their relationship: UI containment hierarchy (a root component that comprises nested containers and components) Container levels and types (such as top-level or intermediate containers) Layout managers and their types (used by each container) Components that can be added into containers

14-10 Copyright © 2005, Oracle. All rights reserved. The Containment Hierarchy Top-level containers –Frame –Dialog –Applet Intermediate containers –Panel –Scroll Pane Atomic components –Label –Text items –Buttons Frame Panel Atomic components

14-11 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-12 Copyright © 2005, Oracle. All rights reserved. Top-Level Containers Swing provides JFrame, JDialog, or JApplet, with changeable properties such as: –A content pane for holding intermediate containers or components, by using the getContentPane() or setContentPane() methods –A border, by using a setBorder() method –A title, by using a setTitle() method –Window decorations such as buttons for closing and minimizing (excludes applets) AWT provides Frame, Dialog, or Applet –These do not provide properties such as a content pane or borders.

14-13 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-14 Copyright © 2005, Oracle. All rights reserved. Intermediate Containers Designed to contain components (or containers): Can be nested within other containers Types of intermediate containers: –Panels for grouping containers or components –Scroll Panes to add scroll bars around components that can grow, such as a list or a text area –Split Panes to display two components in a fixed area, which is adjustable by the user –Tabbed Panes for containing multiple components, showing only one at a time, based on user selection –Tool Bars for grouping components, such as buttons –Internal Frames for nested windows

14-15 Copyright © 2005, Oracle. All rights reserved. Atomic Components Buttons Check boxes Combo boxes Text Lists Labels

14-16 Copyright © 2005, Oracle. All rights reserved. Layout Management Overview

14-17 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-18 Copyright © 2005, Oracle. All rights reserved. Border Layout Has five areas: North, South, West, East, and Center Has center area that expands to fill the available space Displays only one component in each area Makes each area useful for holding intermediate panels

14-19 Copyright © 2005, Oracle. All rights reserved. GridBag Layout Is based on a grid Allows components to span multiple rows and columns Allows rows and columns to differ in size Uses the components preferred size to control cell size

14-20 Copyright © 2005, Oracle. All rights reserved. GridBag Constraints Cell position Cell span Expansion weighting Fill rules Anchoring Component padding External insets

14-21 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-22 Copyright © 2005, Oracle. All rights reserved. Using Layout Managers Layout managers are designed to manage multiple components simultaneously. Using a layout manager with containers requires: –Creating a container and a layout manager object –Setting the layout property of the container –Adding items (components or other containers) into the regions that are defined by the layout manager Different layout managers require different arguments to control component placement.

14-23 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-24 Copyright © 2005, Oracle. All rights reserved. Combining Layout Managers VerticalFlow Grid GridBag null Border

14-25 Copyright © 2005, Oracle. All rights reserved. Using Frames or Dialogs A Java frame is equivalent to an application window. Use the JFrame for a main window –It has properties for icons, title, window decorations for minimize, maximize, and close buttons. –It uses BorderLayout by default. –It provides a default content pane that occupies the center region of the layout. –You can set the frame size with the setSize() method, and make it visible by using the setVisible() method. Use JDialog for a modal window –You must dismiss a modal window before the application that invokes it can become active.

14-26 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-27 Copyright © 2005, Oracle. All rights reserved. Using JPanel Containers JPanel is a general purpose container. Can use any layout manager (uses Flowlayout by default) Can use any border Can have added components or other panels/containers by using the add() method JPanel myPanel = new JPanel(new BorderLayout()); JTextArea jTextArea1 = new JTextArea(); myPanel.setBorder(BorderFactory.createRaisedBevelBorder()); myPanel.add(jTextArea1, BorderLayout.SOUTH);

14-28 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-29 Copyright © 2005, Oracle. All rights reserved. Adding Borders to Components Borders are Swing objects. –Defined in javax.swing.borders Use setBorder() to assign a border to a component. Create borders with the class called javax.swing.BorderFactory. Create borders separately to use with many components. jPanel1.setBorder(BorderFactory.createBevelBorder( BevelBorder.LOWERED,Color.lightGray,Color.darkGray)); Border etchedBorder = BorderFactory.createEtchedBorder();//pre-create border jPanel2.setBorder(etchedBorder); // use border`

14-30 Copyright © 2005, Oracle. All rights reserved. Using Internal Frames An internal frame is the equivalent of a document window that is contained within an application window for multiple-document interface (MDI) window applications. Use JInternalFrame for an internal window: –Similar to JFrame, it can contain intermediate containers and components and use a layout manager. –By default it is not closable, iconifiable, maximizable, or visible. Use a JDesktopPane as the content pane in which the internal frames are added: –Controls the size and placement of internal frames –Uses a null layout manager by default

14-31 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-32 Copyright © 2005, Oracle. All rights reserved. Swing Text Controls

14-33 Copyright © 2005, Oracle. All rights reserved. Adding Components with Oracle JDeveloper 10g Use the wizard to create a JFrame. Select a layout manager. Add components from the Component Palette. Fine-tune component properties.

14-34 Copyright © 2005, Oracle. All rights reserved. Creating a Frame Frame

14-35 Copyright © 2005, Oracle. All rights reserved. Adding Components Use the Component Palette to add Swing items to the Frame

14-36 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-37 Copyright © 2005, Oracle. All rights reserved. Setting Pluggable Look and Feel Swing applications provide support for a different look and feel to adapt to the visual environment of the operating system. The look and feel: Is application-specific: –Can be initialized when the application starts –Can change dynamically Affects lightweight Swing components Supports Win, Mac, Java (Metal) and Motif Uses javax.swing.UIManager class –Provides the setLookAndFeel() method, which accepts a look and feel class name string.

14-38 Copyright © 2005, Oracle. All rights reserved. Notes Page

14-39 Copyright © 2005, Oracle. All rights reserved. Summary In this lesson, you should have learned the following: Frames are top-level containers. Panels are intermediate containers that can be nested. Each container can have its own layout manager. Layout managers control component placement. You can combine layout managers within an application. You can control the applications look and feel.

14-40 Copyright © 2005, Oracle. All rights reserved. Practice 14: Overview This practice covers: Creating a class based on JFrame for the main window of the OrderEntry application –Add a default menu and status bar. –Add a JDesktopPane and set it as the content pane. Creating a class based on JInternalFrame to manage order creation and data entry –Create the container layout hierarchical structure for the order-entry frame components. –Add some of the components to this frame. Setting layout managers for each container

14-41 Copyright © 2005, Oracle. All rights reserved. Notes Page for Practice 14

14-42 Copyright © 2005, Oracle. All rights reserved. Practice 14: Notes

14-43 Copyright © 2005, Oracle. All rights reserved. Practice 14: Notes

14-44 Copyright © 2005, Oracle. All rights reserved. Practice 14: Notes

14-45 Copyright © 2005, Oracle. All rights reserved. Practice 14: Notes

14-46 Copyright © 2005, Oracle. All rights reserved.