Vous êtes sur la page 1sur 17

Graphics Library in JAVA

GRAPHICS LIBRARY IN JAVA


National Institute of Science & Technology

Seminar Project

Under the Guidance of


Mr. Siddhartha B. Neelamani
(Senior Faculty)

Submitted by
Md Suhel Azam Roll no#EC200118097

Md. Suhel Azam


Graphics Library in JAVA

Overview Of Presentation
National Institute of Science & Technology

• What is JGL?
• A set of Java GUI components from Sun
• Included starting with Java 2 SDK1.4.2
• Part of the Java Foundation Classes (JFC)
• The graphics library defines a number of drawing
function, java2d api, java 3d api.
• This graphics class contains two types of subclasses;
those are Debug graphics, Graphics2D.

Md. Suhel Azam


Graphics Library in JAVA

Graphics Class
National Institute of Science & Technology

• The Graphics class is the abstract base class for all graphics
contexts that allow an application to draw onto components
that are realized on various devices, as well as onto off-screen
images.
• A Graphics object encapsulates state information needed for
the basic rendering operations that Java supports
• This 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 (XOR or Paint).

Md. Suhel Azam


Graphics Library in JAVA

Graphics library
National Institute of Science & Technology

Constructor Detail
•Graphics
protected Graphics()
Constructs a new Graphics object. This constructor is the
default constructor for a graphics context. Since Graphics is an
abstract class, applications cannot call this constructor directly.
Graphics contexts are obtained from other graphics contexts or
are created by calling getGraphics on a component.

Md. Suhel Azam


Graphics Library in JAVA

Graphics library
National Institute of Science & Technology

Method Detail
• create
public abstract Graphics create()
translate
public abstract void translate(int x, int y)
• getColor
public abstract Color getColor()
• SetColor
public abstract Color getColor()
• setXORMode
public abstract void setXORMode(Color c1)
• getFont
public abstract Font getFont()

Md. Suhel Azam


Graphics Library in JAVA

Method Detail
National Institute of Science & Technology

• setFont
public abstract void setFont(Font font)
• clipRect
public abstract void clipRect(int x, int y, int width, int height)
• setClip
public abstract void setClip(int x, int y, int width, int height)
• getClip
public abstract Shape getClip()
• setClip
public abstract void setClip(shape clip)
• drawLine
public abstract void drawLine(int x1, int y1, int x2, int y2)

Md. Suhel Azam


Graphics Library in JAVA

Method Detail
National Institute of Science & Technology

• fillRect
public abstract void fillRect(int x, int y, int width, int height)
• drawRect
public void drawRect(int x, int y, int width, int height)
• drawOval
public abstract void drawOval(int x, int y, int width, int height)
• drawArc
public abstract void drawArc(int x, int y, int width, int height, int startAngle,
int arcAngle)
• drawPolyline
public abstract void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
• drawPolygon
public abstract void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
Md. Suhel Azam
Graphics Library in JAVA

Method Detail
National Institute of Science & Technology

• drawString
public abstract void drawString(String str, int x, int y)
• drawChars
public void drawChars(char[] data, int offset, int length, int x, int y)
• drawImage
public abstract boolean drawImage(Image img, int x, int y,
ImageObserver observer)
• dispose
public abstract void dispose()
• getClipRect
public Rectangle getClipRect()

Md. Suhel Azam


Graphics Library in JAVA

Graphics2D
National Institute of Science & Technology

• This Graphics2D class extends the Graphics class to provide


more sophisticated control over geometry, coordinate
transformations, color management, and text layout.
• This is the fundamental class for rendering 2-dimensional
shapes, text and images on the Java(tm) platform
• Coordinate Spaces
All coordinates passed to a Graphics2D object are specified in a
device-independent coordinate system called User Space, which
is used by applications.
Coordinates in device space usually refer to individual device
pixels and are aligned on the infinitely thin gaps between these
pixels.

Md. Suhel Azam


Graphics Library in JAVA

Graphics2D
National Institute of Science & Technology

•Rendering Process
The Rendering Process can be broken down into four
phases that are controlled by the Graphics2D rendering attributes.
The three types of rendering operations are:
•Shape operations
•Text operations
•Image Operations

Md. Suhel Azam


Graphics Library in JAVA

Default Rendering Attributes


National Institute of Science & Technology

The default values for the Graphics2D rendering attributes are:


• Paint
The color of the Component.
• Font
The Font of the Component.
• Stroke
A square pen with a linewidth of 1, no dashing, miter segment joins and square end
caps.
• Transform
The getDefaultTransform for the GraphicsConfiguration of the Component.
• Composite
The AlphaComposite.SRC_OVER rule.
• Clip
No rendering Clip, the output is clipped to the Component.

Md. Suhel Azam


Graphics Library in JAVA

Graphics2D Library
National Institute of Science & Technology

Constructor Detail
• Graphics2D
protected Graphics2D()
Constructs a new Graphics2D object.
Method detail
• draw3DRect
public void draw3DRect(int x,int y,int width,int height,
boolean raised)
• fill3DRect
public void fill3DRect(int x, int y, int width, int height, boolean raised)
• draw
public abstract void draw(Shape s)
• drawString
public abstract void drawString(String str, int x, int y)

Md. Suhel Azam


Graphics Library in JAVA

Method Detail
National Institute of Science & Technology

• drawRenderedImage
public abstract void drawRenderedImage(RenderImage img,
AffineTransform xform)
• drawGlyphVector
public abstract void drawGlyphVector(GlyphVector g,
float x, float y)
• fill
public abstract void fill(Shape s)
• hit
public abstract boolean hit(Rectangle rect, shape s, boolean onStroke)
• getDeviceConfiguration
public abstract GraphicsConfiguration getDeviceConfiguration()

Md. Suhel Azam


Graphics Library in JAVA

Method Detail
National Institute of Science & Technology

• setComposite
public abstract void setComposite(Composite comp)
• setPaint
public abstract void setPaint(Paint paint)
• getBackground
public abstract Color getBackground()
• setBackground
public abstract void setBackground(Color color)
• shear
public abstract void shear(double shx, double shy)
• scale
public abstract void scale(double sx, double sy)

Md. Suhel Azam


Graphics Library in JAVA

Method Detail
National Institute of Science & Technology

• rotate
public abstract void rotate(double theta, double x, double y)
• translate
public abstract void translate(double tx, double ty)
• setPaint
public abstract void setPaint(Paint paint)
• setRenderingHint
public abstract void setRenderingHint(RenderingHints.Key hintKey,
Object hintValue)
• getRenderingHint
public abstract Object getRenderingHint(RenderingHints.Key hintKey)
• addRenderingHints
public abstract void addRenderingHints(Map hints)

Md. Suhel Azam


Graphics Library in JAVA

Conclusion
National Institute of Science & Technology

• Most of these methods could be largely simplified if the Graphics


class supported a setPixel function. This would avoid having to create
a BufferedImage in some cases.
• When you draw a Graphics of a Swing Component you do not directly
access the screen memory but a standard buffer memory. Therefore
the Graphics functions called directly on a Java Swing Component
shouldn't be too slow.
• Again java 2D supports enhanced control over graphics, including
such things as coordinate translations, rotation and scaling. It also
provides advanced imaging features.

Md. Suhel Azam


National Institute of Science & Technology

Md. Suhel Azam


Graphics Library in JAVA

Vous aimerez peut-être aussi