CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.

Slides:



Advertisements
Similar presentations
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Advertisements

Graphical User Interfaces
Java Software Development Paradigm Lecture # 12. Basics of GUI.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
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.
Graphical User Interfaces CS 2110 Spring Ivan Sutherland: “Sketchpad”,
Corresponds with Chapter 12
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
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.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L03 (Chapter 15) Creating.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
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.
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.
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.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Graphical User Interface Components Chapter What You Will Learn Text Areas Text Areas Sliders Sliders Menus Menus –With frames –Pop up menus Look.
CMSC 202 Swing. Fall Introduction to Swing Swing is a Java package used to create GUIs The Java AWT (Abstract Window Toolkit) package is the original.
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 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.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
CIS 068 Welcome to CIS 068 ! Lesson 7: 1.GUIs: JAVA Swing 2.Streams and Files.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Layout Manager Summary
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
University of Limerick1 Software Architecture Java Layout Managers.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Swing Components. Introduction Swing – A set of GUI classes – Part of the Java's standard library –Much better than the previous library: AWT Abstract.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
Review_6 AWT, Swing, ActionListener, and Graphics.
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 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
 Figure illustrates a hierarchy containing many event classes from the package java.awt.event.  Used with both AWT and Swing components.  Additional.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 Lecture 8: User Interface Components with Swing.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
GUIs & Event-Driven Programming Chapter 11 Review.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Graphical User Interface (pronounced "gooey")
Chapter 13: Advanced GUIs and Graphics
Welcome to CIS 068 ! GUIs: JAVA Swing
IFS410: Advanced Analysis and Design
GUI Layouts By: Leonard & Saif.
Advanced GUIs and Graphics
Graphical User Interface
Presentation transcript:

CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing

CIS 068 Overview JAVA and GUIs: SWING –Container, Components, Layouts –Using SWING

CIS 068 The First Swing Program Example: The First Swing Program

CIS 068 The GUI Container: JFrame Layout: BorderLayout North Center Components: JLabel JButton, containing an ImageIcon

CIS 068 Steps to build a GUI 1. import package 2. set up top level container (e.g. JFrame) 3. apply layout (e.g. BorderLayout) 4. add components (e.g. Label, Button) 5. REGISTER listeners 6. show it to the world !

CIS 068 The Source 1. import package 2. set up top level container (e.g. JFrame) 3. apply layout (e.g. BorderLayout) 4. add components (e.g. Label, Button) 5. REGISTER listeners 6. show it to the world !

CIS 068 Swing Components Top Level Containers General Purpose Containers Special Purpose Containers Basic Controls Uneditable Information Displays Interactive Displays of Highly Formatted Information

CIS 068 Swing Components Top Level Containers Your application usually extends one of these classes !

CIS 068 Swing Components General Purpose Containers

CIS 068 Swing Components General Purpose Containers typically used to collect Basic Controls (JButton, JChoiceBox…) Added to layout of top-level containers JPanel JFrame

CIS 068 Swing Components Special Purpose Containers

CIS 068 Swing Components Special Purpose Containers If you want to use them, go to java.sun.com

CIS 068 Swing Components Basic Controls

CIS 068 Swing Components Basic Controls Unlike ‘passive’ containers, controls are the ‘active’ part of your GUI Remark: containers aren’t only ‘passive’, they are also ‘active’ sources of events, eg. Mouse-events. Being the visible part of your interface, controls bring your application to life Controls are event sources ! Objects of your application register to controls to handle the events

CIS 068 Swing Components Uneditable Information Displays

CIS 068 Swing Components Interactive Displays of Highly Formatted Information

CIS 068 Swing Components Interactive Displays of Highly Formatted Information Define standard interfaces for frequently needed tasks... go to java.sun.com for further information...

CIS 068 Layout Management How to glue it all together: The Layout Management

CIS 068 Layout Management The process of determining the size and position of components A layout manager is an object that performs layout management for the components within the container. Layout managers have the final say on the size and position of components added to a container Using the add method to put a component in a container, you must ALWAYS take the container's layout manager into account

CIS 068 Layout Management... and finally, the layout manager preserves the world from home made layout-design !

CIS 068 Layout Management Java supplies five commonly used layout managers: 1.BorderLayout 2.BoxLayout 3.FlowLayout 4.GridBagLayout 5.GridLayout

CIS 068 Layouts BorderLayout Position must be specified, e.g. add (“North”, myComponent)

CIS 068 Layouts BoxLayout The BoxLayout class puts components in a single row or column. It respects the components‘ requested maximum sizes.

CIS 068 Layouts FlowLayout FlowLayout is the default layout manager for every JPanel. It simply lays out components from left to right, starting new rows if necessary

CIS 068 Layouts GridBagLayout GridBagLayout is the most sophisticated, flexible layout manager the Java platform provides. If you really want to use it, go to java.sun.com …

CIS 068 Layouts GridLayout GridLayout simply makes a bunch of components equal in size and displays them in the requested number of rows and columns.

CIS 068 Using Components Examples: Using a JButton Using a JSlider Using a JCheckBox

CIS 068 Using a JButton Some Constructors: JButton() Creates a button with no text or icon JButton(Icon icon) Creates a button with an icon JButton(String text) Creates a button with text JButton(String text, Icon icon) Creates a button with initial text and an icon

CIS 068 Using a JButton Some Methods: addActionListener( ActionListener a) Registers ActionListener to JButton Inherited from AbstractButton setFont(Font font)Specifies Font (Type, Style, Size) Inherited from JComponent setBackground( Color color) Sets background color Inherited from JComponent setActionCommand (String text) Used to specify button if listener is registered to multiple buttons (see ActionEvent.getActionCommand())

CIS 068 Using a JSlider Some Constructors: JSlider() Creates a horizontal slider with the range 0 to 100 and an initial value of 50 JSlider( int min, int max, int value ) Creates a horizontal slider using the specified min, max and value. JSlider( Int orientation int min, int max, int value ) Creates a slider with the specified orientation and the specified minimum, maximum, and initial values.

CIS 068 Using a JSlider Some Methods: addChangeListener (ChangeListener cl) Registers ChangeListener to slider int getValue()Returns the slider’s value setValue(int value)Sets the slider’s value

CIS 068 Using a JCheckBox Some Constructors: JCheckBox()Creates an initially unselected check box button with no text, no icon. JCheckBox( String text) Creates an initially unselected check box with text. JCheckBox( String text, Icon icon, boolean selecte d) Creates a check box with text and icon, and specifies whether or not it is initially selected.

CIS 068 Using a JCheckBox Some Methods: addItemListener (ItemListener il) Registers ItemListener to checkbox Inherited from AbstractButton setSelected( boolean select) Sets the state of checkbox Inherited from AbstractButton boolean getSeleted () Gets the state of checkbox. calling method often saves from registering to the checkbox !

CIS 068 Custom Painting creating your own graphics: Custom Painting

CIS 068 Custom Painting Decide which superclass to use, for example: JPanel: Generating and displaying graphs in top of a blank or transparent background JLabel: Painting on top of an image JButton: custom button … Every class derived from JComponent can be used for custom drawing ! (Recommended: JPanel)

CIS 068 Custom Painting The Graphics Object provides both a context for painting and methods for performing the painting. Example of methods –drawImage –drawString –drawRect –fillRect –setColor –… passed as argument to the paintComponent - method

CIS 068 Custom Painting The paintComponent method Method of class JComponent Inherited to all subclasses, e.g. JPanel, JButton,… The place where all custom painting belongs ! Invoked by the event-scheduler or by the repaint() - method

CIS 068 Using Swing (demo program)

CIS 068 At last... This was a BRIEF overview and introduction to SWING. SWING has MUCH more to offer, see