1 L46 Advanced GUI Component (1). 2 OBJECTIVES  To create and manipulate sliders, and menus,

Slides:



Advertisements
Similar presentations
Chapter 11 Creating User Interfaces F What is JavaBean? F JComponent F JButton  ImageIcon  JLabel  JTextField  JTextArea  JComboBox  JList  JCheckBox.
Advertisements

Graphical User Interfaces (Part IV)
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.
1 Windows CIS*2450 Advancing Computing Techniques.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
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.
 Pearson Education, Inc. All rights reserved GUI Components: Part 2.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
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.
GUI and Event-Driven Programming Part 2. Event Handling An action involving a GUI object, such as clicking a button, is called an event. The mechanism.
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.
Advanced Java Class GUI, part 2. JComponent methods addXXXListener(XXXListener) repaint() – [optional arguments: delay and coordinates of sub-area to.
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.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
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.
1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional.
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.
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.
PROG Object Oriented Programming II PROG Object Oriented Programming II Window Events Multi-screen Applications.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 – Graphical User Interfaces Part 2 Outline.
Graphical User Interface Components Chapter What You Will Learn Text Areas Text Areas Sliders Sliders Menus Menus –With frames –Pop up menus Look.
Dale Roberts GUI Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
SWING. AbstractButton Swing Buttons are subclasses of the AbstractButton class, which extends JComponent. Abstract class javax.swing.AbstractButton AbstractButton.
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.
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.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
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.
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
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.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Field Trip #22 Creating an Excel Spreadsheet with Java By Keith Lynn.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
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.
Creating User Interfaces Chapter 13 CSCI CSCI 1302 – Creating User Interfaces2 Outline Introduction Common Features of Swing GUI Components Buttons.
Creating User Interfaces Event-Driven Programming.
Basics of GUI Programming Chapter 11 and Chapter 22.
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.
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.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
Dale Roberts GUI Programming using Java - Windowing Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
Chapter 1: An Introduction to Visual Basic 2015
Advanced GUIs II CS Lecture
Advanced User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Advanced GUIs II CS Lecture
Advanced GUIs and Graphics
Presentation transcript:

1 L46 Advanced GUI Component (1)

2 OBJECTIVES  To create and manipulate sliders, and menus,

Introduction Pluggable look-and-feel (PLAF) – Swing can customize the look-and-feel of the GUI – Motif A popular UNIX look-and-feel Multiple-document interface (MDI) – A main window (the parent window) containing other windows (child windows) – Manages several open documents parallel

JSlider JSlider – Enables the user to select from a range of integer values – Inherits from JComponent – Contains: Tick marks – Can display major tick marks, minor tick marks and labels for tick marks – Are not displayed by default Thumb – Allows the user to select a value – Snap-to ticks Cause the thumb to snap to the closest tick mark

5 Fig | JSlider component with horizontal orientation. thumb tick mark

JSlider (Cont.) – If a JSlider has the focus (is the currently selected GUI component in the user interface) Left/right arrow keys cause the thumb of the JSlider to decrease/increase by 1 Down/up arrow keys cause the thumb of the JSlider to decrease/increase by 1 PgDn (page down)/PgUp (page up) keys cause the thumb of the JSlider to decrease/increase by block increments of one-tenth of the range of values Home/End keys move the thumb of the JSlider to the minimum/maximum value of the JSlider

JSlider (Cont.) – Can have either horizontal or vertical orientation Minimum value is at the left or bottom end of the JSlider Maximum value is at the right or top end of the JSlider JSlider method setInverted reverses the minimum and maximum value positions – Generate ChangeEvent s in response to user interactions An object of a class that implements interface ChangeListener and declares method stateChanged can respond to ChangeEvent s

8 Outline OvalPanel.java (1 of 2) Used as the width and height of the bounding box in which the circle is displayed Draws a filled circle Change the circle’s diameter and repaint

9 Outline OvalPanel.java (2 of 2) Return the preferred width and height of an OvalPanel Return an OvalPanel ’s minimum width and height

10 Outline SliderFrame.java (1 of 2) Create OvalPanel object myPanel Create JSlider object diameterSlider as a horizontal JSlider with a range of and a initial value of 10 Indicate that each major-tick mark represents 10 values and that the tick marks should be displayed

11 Outline SliderFrame.java (2 of 2) Register a ChangeListener to handle diameterSlider ’s events Method stateChanged is called in response to a user interaction Call myPanel ’s setDiameter method and pass the current thumb position value returned by JSlider method getValue

12 Outline SliderDemo.java

Windows: Additional Notes JFrame – Is a window with a title bar and a border – A subclass of java.awt.Frame Which is a subclass of java.awt.Window – One of the few Swing GUI components that is not a lightweight GUI component – Java application windows look like every other window displayed on that platform

Windows: Additional Notes (Cont.) – JFrame method setDefaultCloseOperation determines what happens when the user closes the window DISPOSE_ON_CLOSE – Dispose of the Window to return resources to the system DO_NOTHING_ON_CLOSE – Indicates that the program will determine what to do when the user indicates that the window should close HIDE_ON_CLOSE – The default – JFrame method setVisible Display the window on the screen – JFrame method setLocation Specify the window’s position when it appears on the screen

Windows: Additional Notes (Cont.) User manipulation of the window generates window events – Method addWindowListener registers event listeners for window events – Interface WindowListener provides seven window- event-handling methods windowActivated – called when the user makes a window the main window windowClosed – called after the window is closed windowClosing – called when the user initiates closing of the window

Windows: Additional Notes (Cont.) windowDeactivated – called when the user makes another window the main window windowDeiconified – called when the user restores a window from being minimized windowIconified – called when the user minimizes a window windowOpened – called when a program first displays a window on the screen

Using Menus with Frames Menus – Allow the user to perform actions without unnecessarily cluttering a GUI with extra components – Can be attached only to objects of the classes that provide member setMenuBar, such as JFrame and JApplet – Class MenuBar Contains the methods necessary to manage a menu bar – Class JMenu Contains the methods necessary for managing menus – Class JMenuItem Contains the methods necessary to manage menu items – Can be used to initiate an action or can be a submenu

Using Menus with Frames (Cont.) – Class JCheckBoxMenuItem Contains the methods necessary to manage menu items that can be toggled on or off – Class JRadioButtonMenuItem Contains the methods necessary to manage menu items that can be toggled on or off like JCheckBoxMenuItem s When multiple JRadioButtonMenuItem s are maintained as part of a ButtonGroup, only one item in the group can be selected at a given time – Mnemonics Special characters that can provide quick access to a menu or menu item from the keyboard

19 Outline MenuFrame.java (1 of 8)

20 Outline MenuFrame.java (2 of 8) Create a JMenu Call JMenu method setMnemonic Add the “ About… ” JMenuItem to fileMenu

21 Outline MenuFrame.java (3 of 8) Create an ActionListener to process aboutItem ’s action event Display a message dialog box Create and add menu item exitItem Register an ActionListener that terminates the application

22 Outline MenuFrame.java (4 of 8) Add fileMenu to a JMenuBar and attach the JMenuBar to the application window Create menu formatMenu Create submenu colorMenu Create JRadioButtonMenuItem array colorItems Create a ButtonGroup to ensure that only one of the menu items is selected at a time Add JRadioButtonMenuItem s to colorMenu and register ActionListener s

23 Outline MenuFrame.java (5 of 8) Invoke AbstractButton method setSelected Add colorMenu to formatMenu and add a horizontal separator line Create JRadioButtonMenuItem array fonts Create a ButtonGroup to ensure that only one of the menu items is selected at a time Add JRadioButtonMenuItem s to colorMenu and register ActionListener s Set default selection and add horizontal separator

24 Outline MenuFrame.java (6 of 8) Create JCheckBoxMenuItem s Add fontMenu to formatMenu and formatMenu to the JMenuBar

25 Outline MenuFrame.java (7 of 8) Determine the selected JRadioButtonMenuItem getSource method returns a reference to the JRadioButtonMenuItem that generated the event

26 Outline MenuFrame.java (8 of 8) Called if the user selects a JCheckBoxMenuItem in the fontMenu Determine whether either or both of the JCheckBoxMenuItem s are selected

27 Outline MenuTest.java (1 of 2) Menu Mnemonic characters Menu bar

28 Outline MenuTest.java (2 of 2) Menu items Expanded submenu Separator line

Using Menus with Frames (Cont.) showMessageDialog method – Specifying the parent window helps determine where the dialog box will be displayed If specified as null, the dialog box appears in the center of the screen Otherwise, it appears centered over the specified parent window – Modal dialog box Does not allow any other window in the application to be accessed until the dialog box is dismissed Dialog boxes are typically modal