AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java. Java AWT components are platform-dependent i.e.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
1 L36 Graphics and Java 2D™ (1). 2 OBJECTIVES  To understand graphics contexts and graphics objects.  To understand and be able to manipulate colors.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 14 Graphics.
©2004 Brooks/Cole Applets Graphics & GUIs. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Graphical Programs Most applications these days are.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Graphics.
GUI programming AWT(Abstract Windows Toolkit)-GUI components library when Java was introduced AWT was replaced by Swing components import javax.swing.*;
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
Lecture 5 Event Handling.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L01 (Chapter 13) Graphics.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics F The architecture.
CS 112 GUI 06 May 2008 Bilkent. Java GUI API Containers: ◦ contain other GUI components. E.g, Window, Panel, Applet, Frame Dialog. Components: ◦ Buttons,
Topics AWT Classes Window Fundamentals Working with Frame Windows Creating a Frame Window in an Applet Creating a Windowed Program Displaying Information.
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 Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Graphics. Graphics Features in Java Topics to be covered Topics to be covered Graphics Basics Graphics Basics Coordinate System Coordinate System Graphics,
AWT Components (Chapter 9) Java Certification Study Group January 21, 1999 Mark Roth.
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.
JAPPLET.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
Lab 6: Shapes & Picture Extended Ellipse & Rectangle Classes Stand-Alone GUI Applications.
Abstract Window Toolkit (AWT) The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include:  A rich set.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
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.
J McQuillan SE204: 2004/2005: Lecture 4slide 1 The Graphics Class Used when we need to draw to the screen Two graphics classes –Graphics –Graphics2D.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
Objectives of This Session
Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
-Sai Phalgun Tatavarthy. Outline What is a “Graphing Calculator”? Graphics, Graphics2D classes Methods of Graphics object Custom Painting The paintComponent()
1 Unit 5 GUI Aum Amriteshwaryai Namah. 2 Overview Shall learn how to reuse the graphics classes provided by Java for constructing Graphical User Interface.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Agenda Java Coordinate Systems. Graphics Class. Drawing on Panels. Drawing Shapes.
Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics ikt403 – Object-Oriented Software Development.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Graphics basic 1. 2 Objectives Understand Java coordinate systems. Draw things using the methods in the Graphics class. Override the paintComponent method.
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Csc Basic Graphical User Interface (GUI) Components.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
AWT Package. Java GUI classes are contained in the java.awt package. Java GUI classes are contained in the java.awt package. A graphical Java program.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Basics of GUI Programming Chapter 11 and Chapter 22.
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
6.1 Coordinates The screen of a computer is a grid of little squares called pixels. The color of each pixel can be set individually, and drawing on the.
CS202 Java Object Oriented Programming GUI Programming – Color and Drawing Methods Chengyu Sun California State University, Los Angeles.
Aum Amriteshwaryai Namah
Fundamental of Java Programming
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
Abstract Window ToolKit (AWT)
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
AWT Components and Containers
APPLET.
Graphics Programming - Frames
Topics Graphical User Interfaces Using the tkinter Module
Advanced GUIs and Graphics
Presentation transcript:

AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java. Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavyweight i.e. its components uses the resources of system. The java.awt package provides classes for AWT api such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc. AWT Classes

Windows Fundamentals The two most common windows are those derived from Panel, which is used by applets, and those derived from Frame, which creates a standard application window. Much of the functionality of these windows is derived from their parent classes. Thus, a description of the class hierarchies relating to these two classes is fundamental to their understanding.

The class hierarchy for Panel and Frame

Component Component is an object having a graphical representation that can be displayed on the screen and that can interact with the user. For examples buttons, checkboxes, list and scrollbars of a graphical user interface. Container Container object is a component that can contain other components. Components added to a container are tracked in a list. The order of the list will define the components' front-to- back stacking order within the container. If no index is specified when adding a component to a container, it will be added to the end of the list. Panel Panel provides space in which an application can attach any other components, including other panels.

Window Window is a rectangular area which is displayed on the screen. In different window we can execute different program and display different data. Window provide us with multitasking environment. A window must have either a frame, dialog, or another window defined as its owner when it's constructed. Frame A Frame is a top-level window with a title and a border. The size of the frame includes any area designated for the border. Frame encapsulates window. It and has a title bar, menu bar, borders, and resizing corners. Canvas Canvas component represents a blank rectangular area of the screen onto which the application can draw. Application can also trap input events from the use from that blank area of Canvas component.

Working with Frame Windows Two of Frame’s constructors: –Frame( ) –Frame(String title) The first form creates a standard window that does not contain a title. The second form creates a window with the title specified by title. Setting the Window’s Dimensions void setSize(int newWidth, int newHeight) void setSize(Dimension newSize) Dimension getSize( ) - obtain the current size of a window

Hiding and Showing a Window After a frame window has been created, it will not be visible until setVisible( ) is called. –void setVisible(boolean visibleFlag) Setting a Window’s Title –void setTitle(String newTitle) Closing a Frame Window –setVisible(false) –windowClosing( )method of the WindowListener interface Examples: AppletFrame.java WindowEvents.java

Working with Graphics A graphics context is encapsulated by the Graphics class and is obtained in two ways: –It is passed to an applet when one of its various methods, such as paint( ) or update( ), is called. –It is returned by the getGraphics( )method of Component The Graphics class defines a number of drawing functions. Each shape can be drawn edge-only or filled. Objects are drawn and filled in the currently selected graphics color, which is black by default. When a graphics object is drawn that exceeds the dimensions of the window, output is automatically clipped.

Drawing Lines void drawLine(int startX, int startY, int endX, int endY) Eg: Lines.java Drawing Rectangles void drawRect(int top, int left, int width, int height) void fillRect(int top, int left, int width, int height) void drawRoundRect(int top, int left, int width, int height,int xDiam, int yDiam) void fillRoundRect(int top, int left, int width, int height,int xDiam, int yDiam) Drawing Ellipses and Circles void drawOval(int top, int left, int width, int height) void fillOval(int top, int left, int width, int height) Drawing Arcs void drawArc(int top, int left, int width, int height, int startAngle,int sweepAngle) void fillArc(int top, int left, int width, int height, int startAngle,int sweepAngle) Drawing Polygons void drawPolygon(intx[ ], inty[ ], int numPoints) void fillPolygon(intx[ ], inty[ ], int numPoints) Eg: HourGlass.java

Sizing Graphics getSize( ) - returns the dimensions of the window encapsulated within a Dimension object. Eg. ResizeMe.java

Working with Colors - portable, device-independent fashion eg: ColorDemo.java Color defines several constants to specify a number of common colors. Own color creation. Three commonly used forms are shown here: –Color(int red, int green, int blue) –Color(int rgbValue) –Color(float red, float green, float blue) –Eg: new Color(255, 100, 100); Color Methods –Using Hue, Saturation, and Brightness static int HSBtoRGB(float hue, float saturation, float brightness) static float[ ] RGBtoHSB(int red, int green, int blue, float values[ ]) int getRed( ) int getGreen( ) int getBlue( ) - returns the RGB color component found in the invoking Color object in the lower 8 bits of an integer. int getRGB( ) Setting the Current Graphics Color –void setColor(Color newColor) –Color getColor( )

Setting the Paint Mode eg: XOR.java The paint mode determines how objects are drawn in a window. New output to a window overwrites any preexisting contents. void setXORMode(Color xorColor) The advantage of XOR mode is that the new object is always guaranteed to be visible no matter what color the object is drawn over. To return to overwrite mode, call setPaintMode(),void setPaintMode( )

Working with Fonts The AWT provides flexibility by –abstracting font-manipulation operations and –allowing for dynamic selection of fonts. Fonts have a family name, a logical font name, and a face name. The family name is the general name of the font, such as Courier. The logical name specifies a category of font, such as Monospaced. The face name specifies a specific font, such as Courier Italic. Fonts are encapsulated by the Font class.

Determining the Available Fonts eg: ShowFonts.java –String[ ] getAvailableFontFamilyNames( ) –Font[ ] getAllFonts( ) –static GraphicsEnvironment getLocalGraphicsEnvironment( ) Creating and Selecting a Font eg SampleFonts.java –Font(String fontName, int fontStyle, int pointSize) Font style: Font.PLAIN,Font.BOLD, andFont.ITALIC. –void setFont(Font fontObj) Obtaining Font Information eg: FontInfo.java –Font getFont( )

Managing Text output using FontMetrics FontMetrics defines several methods that help you manage text output. –Displaying Multiple Lines of Text –Centering Text –Multiline Text Alignment