Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

15 Copyright © 2005, Oracle. All rights reserved. Adding User Interface Components and Event Handling.
Graphical User Interfaces (Part IV)
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
 What are the basic GUI components we’ve learned so far? › JFrame › JPanel › JButton › JLabel › JTextArea › JTextField › JCheckBox › JRadioButton › Paint.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Exploring the Basics of Windows XP. Objectives Start Windows XP and tour the desktop Explore the Start menu Run software programs, switch between them,
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.
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.
Graphical User Interface (GUI) Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 L46 Advanced GUI Component (1). 2 OBJECTIVES  To create and manipulate sliders, and menus,
Advanced Java Class GUI, part 2. JComponent methods addXXXListener(XXXListener) repaint() – [optional arguments: delay and coordinates of sub-area to.
Computing Fundamentals Module Lesson 9 — Using Windows Explorer
Exploring the Basics of Windows XP
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
®® Microsoft Windows 7 for Power Users Tutorial 2p2 Customizing Microsoft Windows 7.
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.
C51BR Applications of Spreadsheets 1 Chapter 16 Getting Started Making Charts.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Chapter 8: Writing Graphical User Interfaces
Introduction to Matlab & Data Analysis
MVC and Swing IAT 351 Week 7 Lecture/tutorial Lyn Bartram.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
CS377A: A Programming Approach to HCI Jan Borchers Spring Swing Refresher David Merrill 5/14/2002
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
XP New Perspectives on Windows XP Tutorial 1 Exploring the Basics.
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.
Computing Fundamentals Module Lesson 3 — Changing Settings and Customizing the Desktop Computer Literacy BASICS.
Copyright © 2010 Wolters Kluwer Health | Lippincott Williams & Wilkins Introduction to Windows Chapter 2.
Graphical User Interface Components Chapter What You Will Learn Text Areas Text Areas Sliders Sliders Menus Menus –With frames –Pop up menus Look.
CSE 219 Patterns in Programming More Design Patterns.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Office graphic copyright by Microsoft Corp.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Topics Introduction Scene Graphs
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Swing / Session1 / 1 of 30 Module Introduction Distributed Computing in Java.
User Interface Components Lecture # 5 From: interface-elements.html.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Swinging in Your Java Playground. Background Swing is a part of the Java Foundation Classes (JFC). The JFC is made up of features intended to give a programmer.
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.
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.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
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.
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.
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
Menus Pull-downs and popups. Tooltips –a ToolTip is a context-sensitive text string that is displayed in a popup window when the mouse rests over a particular.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
Lesson 13 Tables. Overview Create a table. Key and edit text in tables. Select cells, rows, and columns. Edit table structures. Format tables and cell.
Advanced User Interfaces
Chapter 8: Writing Graphical User Interfaces
Presentation transcript:

Swing - 2 Session 13

Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus

Swing - 2 / 3 of 38 Objectives (2) KeyStroke handling, Action Objects, Nested Containers Virtual Desktops, Compound Borders Drag and Drop Java 2D Customized Dialogs, Standard Dialog classes Discuss features of Swing such as:

Swing - 2 / 4 of 38 A Swing menu consists of a menubar, menuitems and menus Menubar is the root of all menus and menuitems Menus show a list of items that indicate various tasks Select or click an option and another list or sub-menu opens up Menus

Swing - 2 / 5 of 38 JFC Menus components

Swing - 2 / 6 of 38 Hierarchy JMenuBarJPopupMenuJAbstractButtonJSeperator JMenuItem JMenuJCheckBoxMenuItemJRadioButtonMenuItem JComponent Container Component Object

Swing - 2 / 7 of 38 JMenuBar Consists of a number of JMenus with each JMenu represented as a string within the JMenuBar JMenuBar requires: ‘SingleSelectionModel’ – keeps track of the menu currently selected ‘LookAndFeel’ class – Responsible for drawing the menu bar and responding to events that occur in it JMenuBar is a component that can be added to a container through a JFrame, JWindow or JInternalFrame’s rootpane.

Swing - 2 / 8 of 38 JMenu JMenu has two additional classes: JPopupMenu – Used to display the JMenu’s menu items LookAndFeel – Responsible for drawing the menu in the menubar and for responding to all events that occur in it JMenu is seen as a text string under JMenuBar while it acts as a popup menu when the user clicks on it

Swing - 2 / 9 of 38 JMenu - Example Output

Swing - 2 / 10 of 38 JPopupMenu Used for the “pull-right” menu It is also used as a shortcut menu, which is activated by the right click of the mouse The constructors used to create JPopupMenu are: public JPopupMenu() – creates a JPopupMenu public JPopupMenu(String label) – creates a JPopupMenu with the specified title Displays expanded form of menu

Swing - 2 / 11 of 38 Functions of JPopupMenu Determines whether the mouse event is the popup trigger for the platform public boolean isPopupTrigger() Displays the popup menu at the position (x,y) in the coordinate space of the component “c” public void show(Component c, int x, int y) Creates a new menu item with the specified text and appends it to the end of the menu public JMenuItem add(String s) Appends the specified menu item at the end of the menu public JMenuItem add(JMenuItem menuItem) PurposeMethod

Swing - 2 / 12 of 38 JPopupMenu – Example (1)

Swing - 2 / 13 of 38 JPopupMenu – Example (2)

Swing - 2 / 14 of 38 JPopupMenu – Example (3)

Swing - 2 / 15 of 38 JPopupMenu – Example (4) Output

Swing - 2 / 16 of 38 JMenuItem A component that appears as a text string possibly with an icon in a JMenu or JPopupMenu Dialog Box JMenuItem dissapears

Swing - 2 / 17 of 38 JMenuItem - Example Output

Swing - 2 / 18 of 38 JCheckBoxMenuItem Checkboxes are created using JCheckBox class May have a text string and/or an icon When a JCheckBoxMenuItem is clicked and released, the state of a menu item changes to selected or deselected Contains checkboxes as its items

Swing - 2 / 19 of 38 JRadioButtonMenuItem May have a text string and/or an icon Clicking a selected radio button does not change its state Clicking an unselected radio button deselects the earlier selected one Similar to checkboxes except that only one radio button can be selected at any point of time

Swing - 2 / 20 of 38 Example (1)

Swing - 2 / 21 of 38 Example (2)

Swing - 2 / 22 of 38 Example (3) Output

Swing - 2 / 23 of 38 Trees Windows Explorer has a tree like structure depicting files and folders Windows Explorer structures can be created in Java using JTree Every row in the hierarchy is termed as a node By default, the tree displays the root node A node having child nodes is called a branch node else it is called as a leaf node A Tree depicts information in a hierarchical, vertical manner

Swing - 2 / 24 of 38 JTree – Example (1)

Swing - 2 / 25 of 38 JTree – Example (2) Output When the nodes are clicked

Swing - 2 / 26 of 38 Tables Useful in storing numerical data Certain computer applications require tables to display data allowing the user to edit them JTable class in Swing enables us to create tables JTable does not store data, it only provides a view of it Volumes of data are better maintained in a tabular format than as a list

Swing - 2 / 27 of 38 JTable - Example Output

Swing - 2 / 28 of 38 Progress Bars A better way to do the same is by using charts or bar graphs Certain programs provide a graphical indication of a task that is currently under progress Swing uses JProgressBar class to implement the same Monitoring the progress of any activity can be done by using percentage figures

Swing - 2 / 29 of 38 Progress Bars – Example (1)

Swing - 2 / 30 of 38 Progress Bars – Example (2) Output

Swing - 2 / 31 of 38 MVC To achieve this, Swing components work within the MVC model MVC model stands for: Model View Controller Swing helps to specify the look and feel, such as the Java look and feel, Windows look and feel

Swing - 2 / 32 of 38 Interaction between MVC Model Controller View View reads the contents Informs view of state change Informs the view to update visuals Update the contents

Swing - 2 / 33 of 38 Characteristics common to Swing Components Visual appearance - determines what the component should look like Behavior - decides how the component should respond to events Content - decides on the state of the component

Swing - 2 / 34 of 38 MVC classes View – Responsible for showing the component on the basis of the state Controller – Handles the event Interaction between the classes are controlled by the MVC pattern Each class has necessary methods defined within them Model – Stores the data or the state of the object

Swing - 2 / 35 of 38 MVC - Example Controller Event notification ModelView Calls necessary files to make changes Informs about the change of state Redraws the component

Swing - 2 / 36 of 38 Swing features (1) Since the fundamental class JComponent contains a RootPane, any component can be nested within another KeyStrokeHandling, ActionObjects, Nested Containers Keystrokes can be captured by creating a KeyStroke object Action interface extends ActionListener specifying an enabled property as well as properties for text descriptions

Swing - 2 / 37 of 38 Swing Features (2) Facilitates transfer of data between Java applications as well as to native applications Virtual Desktops and Compound Borders JDesktopPane and JInternalFrame classes can be used to create a virtual desktop Compound borders are created by combining various border styles Drag and Drop

Swing - 2 / 38 of 38 Swing Features (3) Using Java 2D API, one can: Create lines of any thickness Use different gradients and textures to fill shapes Move, rotate, scale and trim text and graphics Combine overlapping text and graphics Customized Dialogs and Standard Dialog classes Makes use of JOptionPane class Standard dialog classes available are: JFileChooser JColorChooser Java 2D