AWT GRAPHICS CLASS. Introduction. Class declaration. Class constructors. Class methods

Similar documents
AWT QUADCURVE2D CLASS

AWT COLOR CLASS. Introduction. Class declaration. Field

AWT DIALOG CLASS. Dialog control represents a top-level window with a title and a border used to take some form of input from the user.

AWT WINDOW CLASS. The class Window is a top level window with no border and no menubar. It uses BorderLayout as default layout manager.

AWT CHECKBOX CLASS. Creates a check box with the specified label and sets the specified state.

AWT CHOICE CLASS. Choice control is used to show pop up menu of choices. Selected choice is shown on the top of the menu.

AWT SCROLLBAR CLASS. Scrollbar control represents a scroll bar component in order to enable user to select from range of values.

AWT TEXTFIELD CLASS. Constructs a new empty text field with the specified number of columns.

AWT LIST CLASS. The List represents a list of text items. The list can be configured to that user can choose either one item or multiple items.

SWING - GROUPLAYOUT CLASS

AWT MENUBAR CLASS. Introduction. Class declaration. Class constructors. Class methods

Graphics and Painting

Lecture 7 A First Graphic Program And Data Structures & Drawing

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

The AWT Package, Graphics- Introduction to Images

The AWT Package, An Overview

IT101. Graphical User Interface

Java Applet Basics. Life cycle of an applet:

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Chapter 12 Advanced GUIs and Graphics

G51PRG: Introduction to Programming Second semester Applets and graphics

Computer Science 210: Data Structures. Intro to Java Graphics

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Swing from A to Z Some Simple Components. Preface

8. Polymorphism and Inheritance

Java TM Applets. Rex Jaeschke

Unit 7: Event driven programming

Control Statements: Part Pearson Education, Inc. All rights reserved.

Graphics Applets. By Mr. Dave Clausen

Road Map. Introduction to Java Applets Review applets that ship with JDK Make our own simple applets

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

Windows and Events. created originally by Brian Bailey

Java Coordinate System

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Chapter 3: Inheritance and Polymorphism

GWT - UIOBJECT CLASS

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Swing from A to Z Using Focus in Swing, Part 2. Preface

9. APPLETS AND APPLICATIONS

Chapter 1 GUI Applications

GUAVA - RANGE CLASS. Range represents an interval or a sequence. It is used to get a set of numbers/ strings lying in a particular range.

Part 3: Graphical User Interface (GUI) & Java Applets

Graphics -- To be discussed

GUAVA - CHARMATCHER CLASS

CS 11 java track: lecture 3

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1

The AWT Package, Placing Components in Containers, CardLayout. Preface. Introduction

DCS235 Software Engineering Exercise Sheet 2: Introducing GUI Programming

Graphics Applets. By Mr. Dave Clausen

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Lecture 5: Java Graphics

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Example 3-1. Password Validation

JAVA MOCK TEST JAVA MOCK TEST II

7. Program Frameworks


CS1004: Intro to CS in Java, Spring 2005

TWO-DIMENSIONAL FIGURES

CSCE3193: Programming Paradigms

Week 5: Images & Graphics. Programming of Interactive Systems. JavaFX Images. images. Anastasia Bezerianos. Anastasia Bezerianos

Java Object Oriented Design. CSC207 Fall 2014

Graphics in Swing. Engineering 5895 Faculty of Engineering & Applied Science Memorial University of Newfoundland

Lecture 3: Java Graphics & Events

This page intentionally left blank

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM

Inheritance and Polymorphism

CISC 3115 Modern Programming Techniques Spring 2018 Section TY3 Exam 2 Solutions

Some classes and interfaces used in this chapter from Java s original graphics capabilities and from the Java2D API.

The Nervous Shapes Example

L4,5: Java Overview II

Person class. A class can be derived from an existing class by using the form

Introduction. Overview of the Course on Java. Overview of Part 1 of the Course

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Building a Java First-Person Shooter

Creating a Graphical LED cluster bean IBM Visual Age for Java - Creating Custom Beans

15CS45 : OBJECT ORIENTED CONCEPTS

Using the API: Introductory Graphics Java Programming 1 Lesson 8

Chapter 1 Introduction to Java

BSc. (Hons.) Software Engineering. Examinations for / Semester 2

Introduction to Programming Using Java (98-388)

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API

Person class. A class can be derived from an existing class by using the form

INHERITANCE. Spring 2019

2. (True/False) All methods in an interface must be declared public.

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

G Programming Languages - Fall 2012

Inheritance. Inheritance

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

4 Fundamental Issues in Multimedia Programming

Dr. Hikmat A. M. AbdelJaber

Graphic User Interfaces. - GUI concepts - Swing - AWT

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS

Beyond CSE143. What s Left To Do? Templates. Using Templates. A Template Class. A Problem with Reusing Code CSE 143

1. Create a map of the layer and attribute that needs to be queried

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

GUI Output. Adapted from slides by Michelle Strout with some slides from Rick Mercer. CSc 210

Admin. CS 112 Introduction to Programming. Recap: OOP Analysis. Software Design and Reuse. Recap: OOP Analysis. Inheritance

Transcription:

AWT GRAPHICS CLASS http://www.tutorialspoint.com/awt/awt_graphics_class.htm Copyright tutorialspoint.com Introduction The Graphics class is the abstract super class for all graphics contexts which allow an application to draw onto components that can be realized on various devices, or onto off-screen images as well. A Graphics object encapsulates all state information required for the basic rendering operations that Java supports. State information includes the following properties. The Component object on which to draw. A translation origin for rendering and clipping coordinates. The current clip. The current color. The current font. The current logical pixel operation function. The current XOR alternation color Class declaration Following is the declaration for java.awt.graphics class: public abstract class Graphics extends Object Class constructors S.N. 1 Constructor & Description Graphics Constructs a new Graphics object. Class methods S.N. 1 Method & Description abstract void clearrectintx, inty, intwidth, intheight Clears the specified rectangle by filling it with the background color of the current drawing surface. 2 abstract void cliprectintx, inty, intwidth, intheight Intersects the current clip with the specified rectangle. 3

3 abstract void copyareaintx, inty, intwidth, intheight, intdx, intdy Copies an area of the component by a distance specified by dx and dy. 4 abstract Graphics create Creates a new Graphics object that is a copy of this Graphics object. 5 Graphics createintx, inty, intwidth, intheight Creates a new Graphics object based on this Graphics object, but with a new translation and clip area. 6 abstract void dispose Disposes of this graphics context and releases any system resources that it is using. 7 void draw3drectintx, inty, intwidth, intheight, booleanraised Draws a 3-D highlighted outline of the specified rectangle. 8 abstract void drawarcintx, inty, intwidth, intheight, intstartangle, intarcangle Draws the outline of a circular or elliptical arc covering the specified rectangle. 9 void drawbytesbyte[]data, intoffset, intlength, intx, inty Draws the text given by the specified byte array, using this graphics context's current font and color. 10 void drawcharschar[]data, intoffset, intlength, intx, inty Draws the text given by the specified character array, using this graphics context's current font and color. 11 abstract boolean drawimageimageimg, intx, inty, Colorbgcolor, ImageObserverobserver Draws as much of the specified image as is currently available. 12 abstract boolean drawimageimageimg, intx, inty, ImageObserverobserver Draws as much of the specified image as is currently available. 13 abstract boolean drawimage Imageimg, intx, inty, intwidth, intheight, Colorbgcolor, ImageObserverobserver Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.

14 abstract boolean drawimageimageimg, intx, inty, intwidth, intheight, ImageObserverobserver Draws as much of the specified image as has already been scaled to fit inside the specified rectangle. 15 abstract boolean drawimage Imageimg, intdx1, intdy1, intdx2, intdy2, intsx1, intsy1, intsx2, intsy2, Colorbgcolor, ImageObserverobserver Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface. 16 abstract boolean drawimage Imageimg, intdx1, intdy1, intdx2, intdy2, intsx1, intsy1, intsx2, intsy2, ImageObserverobserver Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface. 17 abstract void drawlineintx1, inty1, intx2, inty2 Draws a line, using the current color, between the points x1, y1 and x2, y2 in this graphics context's coordinate system. 18 abstract void drawovalintx, inty, intwidth, intheight Draws the outline of an oval. 19 abstract void drawpolygonint[]xpoints, int[]ypoints, intnpoints Draws a closed polygon defined by arrays of x and y coordinates. 20 void drawpolygonpolygonp Draws the outline of a polygon defined by the specified Polygon object. 21 abstract void drawpolylineint[]xpoints, int[]ypoints, intnpoints Draws a sequence of connected lines defined by arrays of x and y coordinates. 22 void drawrectintx, inty, intwidth, intheight Draws the outline of the specified rectangle. 23 abstract void drawroundrectintx, inty, intwidth, intheight, intarcwidth, intarcheight Draws an outlined round-cornered rectangle using this graphics context's current color. 24 abstract void drawstringattributedcharacteriteratoriterator, intx, inty Renders the text of the specified iterator applying its attributes in accordance with the

specification of the TextAttribute class. 25 abstract void drawstringstringstr, intx, inty Draws the text given by the specified string, using this graphics context's current font and color. 26 void fill3drectintx, inty, intwidth, intheight, booleanraised Paints a 3-D highlighted rectangle filled with the current color. 27 abstract void fillarcintx, inty, intwidth, intheight, intstartangle, intarcangle Fills a circular or elliptical arc covering the specified rectangle. 28 abstract void fillovalintx, inty, intwidth, intheight Fills an oval bounded by the specified rectangle with the current color. 29 abstract void fillpolygonint[]xpoints, int[]ypoints, intnpoints Fills a closed polygon defined by arrays of x and y coordinates. 30 void fillpolygonpolygonp Fills the polygon defined by the specified Polygon object with the graphics context's current color. 31 abstract void fillrectintx, inty, intwidth, intheight Fills the specified rectangle. 32 abstract void fillroundrectintx, inty, intwidth, intheight, intarcwidth, intarcheight Fills the specified rounded corner rectangle with the current color. 33 void finalize Disposes of this graphics context once it is no longer referenced. 34 abstract Shape getclip Gets the current clipping area. 35 abstract Rectangle getclipbounds Returns the bounding rectangle of the current clipping area.

36 Rectangle getclipboundsrectangler Returns the bounding rectangle of the current clipping area. 37 Rectangle getcliprect Deprecated. As of JDK version 1.1, replaced by getclipbounds. 38 abstract Color getcolor Gets this graphics context's current color. 39 abstract Font getfont Gets the current font. 40 FontMetrics getfontmetrics Gets the font metrics of the current font. 41 abstract FontMetrics getfontmetricsfontf Gets the font metrics for the specified font. 42 boolean hitclipintx, inty, intwidth, intheight Returns true if the specified rectangular area might intersect the current clipping area. 43 abstract void setclipintx, inty, intwidth, intheight Sets the current clip to the rectangle specified by the given coordinates. 44 abstract void setclipshapeclip Sets the current clipping area to an arbitrary clip shape. 45 abstract void setcolorcolorc Sets this graphics context's current color to the specified color. 46 abstract void setfontfontfont Sets this graphics context's font to the specified font. 47 abstract void setpaintmode Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color.

48 abstract void setxormodecolorc1 Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color. 49 String tostring Returns a String object representing this Graphics object's value. 50 abstract void translateintx, inty Translates the origin of the graphics context to the point x, y in the current coordinate system. Methods inherited This class inherits methods from the following classes: java.lang.object Graphics Example Create the following java program using any editor of your choice in say D:/ > AWT > com > tutorialspoint > gui > AWTGraphicsDemo.java package com.tutorialspoint.gui; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; public class AWTGraphicsDemo extends Frame { public AWTGraphicsDemo(){ super("java AWT Examples"); preparegui(); public static void main(string[] args){ AWTGraphicsDemo awtgraphicsdemo = new AWTGraphicsDemo(); awtgraphicsdemo.setvisible(true); private void preparegui(){ setsize(400,400); addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent windowevent){ System.exit(0); ); @Override public void paint(graphics g) { g.setcolor(color.gray); Font font = new Font("Serif", Font.PLAIN, 24); g.setfont(font); g.drawstring("welcome to TutorialsPoint", 50, 150);

Compile the program using command prompt. Go to D:/ > AWT and type the following command. D:\AWT>javac com\tutorialspoint\gui\awtgraphicsdemo.java If no error comes that means compilation is successful. Run the program using following command. D:\AWT>java com.tutorialspoint.gui.awtgraphicsdemo Verify the following output Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js