Advanced GUIs and Graphics

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 17 Creating User Interfaces.
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
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.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
©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.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
1 Creating User Interfaces. 2 Motivations A graphical user interface (GUI) makes a system user-friendly and easy to use. Creating a GUI requires creativity.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Java Applets. Applets The term Applet refers to a little application. In JAVA the applet is a java program that is embedded within a HTML document and.
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.
JAPPLET.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
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.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
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.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
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.
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.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7-3 ( Book Chapter 14) GUI and Event-Driven Programming.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Java Programming: Guided Learning with Early Objects Chapter 8 Applications of Arrays (Sorting and Searching) and Strings.
Java Applet What is a Java Applet? How is applet compiled?
Java Applets.
Christopher Budo, Davis Nygren, spencer franks, Luke miller
“Form Ever Follows Function” Louis Henri Sullivan
Java Applets.
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Chapter 7 Creating User Interfaces
AWT Components and Containers
Java Applets.
Java Applets.
Graphical User Interface
Chapter 7-3 (Book Chapter 14)
Chapter 17 Creating User Interfaces
Chapter 17 Creating User Interfaces
Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Advanced GUIs and Graphics Java Programming: From Problem Analysis to Program Design, 3e Chapter 13 Advanced GUIs and Graphics

Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class Color Java Programming: From Problem Analysis to Program Design, 3e

Chapter Objectives (continued) Learn to use additional Layout managers Become familiar with more GUI components Learn how to create menu-based programs Explore how to handle key and mouse events Java Programming: From Problem Analysis to Program Design, 3e

Inheritance Hierarchy of GUI Classes Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Component Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Component (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Component (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Component (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Container Java Programming: From Problem Analysis to Program Design, 3e

Applets Applet: a Java program that is embedded within a Web page and executed by a Web browser Create an applet by extending the class JApplet class JApplet contained in package javax.swing Java Programming: From Problem Analysis to Program Design, 3e

Members of class JApplet Java Programming: From Problem Analysis to Program Design, 3e

Members of class Japplet (continued) Java Programming: From Problem Analysis to Program Design, 3e

Applets (continued) No main method Methods init, start, and paint guaranteed to be invoked in sequence To develop an applet Override any/all of the methods above Java Programming: From Problem Analysis to Program Design, 3e

Applet Methods init Method paint Method Initializes variables Gets data from user Places various GUI components paint Method Performs output Java Programming: From Problem Analysis to Program Design, 3e

Skeleton of a Java Applet import java.awt.Graphics; import javax.swing.JApplet; public class WelcomeApplet extends JApplet { } Java Programming: From Problem Analysis to Program Design, 3e

Applet Displaying Welcome Message //Welcome Applet import java.awt.Graphics; import javax.swing.JApplet; public class WelcomeApplet extends JApplet { public void paint(Graphics g) super.paint(g); //Line 1 g.drawString("Welcome to Java Programming" , 30, 30); //Line 2 } Java Programming: From Problem Analysis to Program Design, 3e

HTML to Run Applet Java Programming: From Problem Analysis to Program Design, 3e

class Font Shows text in different fonts Contained in package java.awt Available fonts Serif/SanSerif Monospaced Dialog/DialogInput Arguments for constructor String specifying the Font face name int value specifying Font style int value specifying Font size Expressed in points (72 points = 1 inch) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Font Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Font (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Font (continued) Java Programming: From Problem Analysis to Program Design, 3e

class Color Shows text in different colors Changes background color of component Contained in package java.awt Java Programming: From Problem Analysis to Program Design, 3e

Constructors of the class Color Java Programming: From Problem Analysis to Program Design, 3e

Constructors of the class Color (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constants Defined in the class Color Java Programming: From Problem Analysis to Program Design, 3e

Constants Defined in the class Color (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constants Defined in the class Color (continued) Java Programming: From Problem Analysis to Program Design, 3e

class Graphics Provides methods for drawing items such as lines, ovals, and rectangles on the screen Contains methods to set the properties of graphic elements including clipping area, fonts, and colors Contained in the package java.awt Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Graphics Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Graphics (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Graphics (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Graphics (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Graphics (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Graphics (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Graphics (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of the class Graphics (continued) Java Programming: From Problem Analysis to Program Design, 3e

Differences Between Applets and GUI Applications Derived from JApplet No main method Uses init method Displayed by HTML Sets title in HTML Size set in HTML Applet closes when HTML doc closes GUI applications class extends JFrame Invokes main method Uses constructors Uses method setVisible Uses setTitle method Uses method setSize Closes with Exit button Java Programming: From Problem Analysis to Program Design, 3e

Converting a GUI Application to an Applet Change JFrame to JApplet Change constructor to method init Remove method calls such as setVisible, setTitle, setSize Remove the method main If applicable, remove Exit button/all code associated with it (e.g. action listener) Java Programming: From Problem Analysis to Program Design, 3e

Additional GUI Components JTextArea JCheckBox JRadioButton JComboBox JList Java Programming: From Problem Analysis to Program Design, 3e

JTextArea Can collect multiple lines of input from user Can display multiple lines of output Pressing Enter key separates lines of text Each line ends with newline character ‘\n’ Derived from class JTextComponent Java Programming: From Problem Analysis to Program Design, 3e

JTextArea (continued) Java Programming: From Problem Analysis to Program Design, 3e

Methods Inherited by class JTextArea from Parent class JTextComponent Java Programming: From Problem Analysis to Program Design, 3e

JTextArea Example Java Programming: From Problem Analysis to Program Design, 3e

JCheckBox User selects from predefined values Example of a toggle button Clicking JCheckBox generates item event Use interface ItemListener and its abstract method itemStateChanged to handle event Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of class JCheckBox Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of class JCheckBox (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of class JCheckBox (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors and Methods of class JCheckBox (continued) Java Programming: From Problem Analysis to Program Design, 3e

JRadioButton Created same way as check boxes Placed in content pane of applet Forces user to select only one radio button at a time You create a button group to group radio buttons Generates an ItemEvent interface ItemListener and method itemStateChanged used to handle events Java Programming: From Problem Analysis to Program Design, 3e

JRadioButton (continued) Java Programming: From Problem Analysis to Program Design, 3e

JRadioButton (continued) Java Programming: From Problem Analysis to Program Design, 3e

JRadioButton (continued) Java Programming: From Problem Analysis to Program Design, 3e

JRadioButton (continued) Java Programming: From Problem Analysis to Program Design, 3e

JComboBox Commonly known as a drop-down list Used to select an item from a list of possibilities Generates an ItemEvent Event monitored by ItemListener ItemListener invokes method itemStateChanged Java Programming: From Problem Analysis to Program Design, 3e

Constructors of class JComboBox Java Programming: From Problem Analysis to Program Design, 3e

Applet with JCheckBox, JComboBox, and JRadioButton Java Programming: From Problem Analysis to Program Design, 3e

Constructors of class JList Java Programming: From Problem Analysis to Program Design, 3e

Constructors of class Jlist (continued) Java Programming: From Problem Analysis to Program Design, 3e

Constructors of class Jlist (continued) Java Programming: From Problem Analysis to Program Design, 3e

Layout Managers FlowLayout GridLayout Default layout manager Places components from left to right, center by default, until no more items can be placed Can align each line left, center, or right Default alignment: LEFT GridLayout Similar to FlowLayout All rows (columns) have same number of components All components have the same size Java Programming: From Problem Analysis to Program Design, 3e

Layout Managers (continued) BorderLayout Items placed into one of 5 specific regions NORTH/SOUTH EAST/WEST CENTER NORTH and SOUTH components extend horizontally (completely span one edge to the other) EAST and WEST components extend vertically between components in NORTH and SOUTH regions CENTER component expands to occupy any unused regions Java Programming: From Problem Analysis to Program Design, 3e

Menus Allow for various functions without cluttering GUI with too many components Can be attached to objects such as JFrame and JApplet (setJMenuBar method) To set a menu bar private JMenuBar menuMB = new JMenuBar(); setJMenuBar(menuMB); Add menus to menu bar; add menu items to menu Order of menus added = Order of appearance Java Programming: From Problem Analysis to Program Design, 3e

Key and Mouse Events Java Programming: From Problem Analysis to Program Design, 3e

Chapter Summary Creating Applets class Font class Graphics class Color Differences between Applet and GUI application Converting GUI application to Applet Java Programming: From Problem Analysis to Program Design, 3e

Chapter Summary (continued) GUI components JTextArea JCheckBox JRadioButton Layout managers Menus Key and mouse events Java Programming: From Problem Analysis to Program Design, 3e