0% found this document useful (0 votes)
22 views

Graphic Programming

This document discusses how to perform custom drawing in Java by using the Graphics class. It describes the different drawing methods available to draw text, lines, shapes, images and more. Methods like drawString, drawLine, drawRect, fillOval and drawImage are covered.

Uploaded by

Dipendra Km
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Graphic Programming

This document discusses how to perform custom drawing in Java by using the Graphics class. It describes the different drawing methods available to draw text, lines, shapes, images and more. Methods like drawString, drawLine, drawRect, fillOval and drawImage are covered.

Uploaded by

Dipendra Km
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

GRAPHIC

PROGRAMMING
Graphic programming

■ This chapter shows you how you can paint your own custom drawing because
you cannot find standard GUI components that meets your requirements.
Java.awt.graphics

■ A graphics context provides the capabilities of drawing on the screen. The graphics
context maintains states such as the color and font used in drawing, as well as
interacting with the underlying operating system to perform the drawing. In Java,
custom painting is done via the java.awt.Graphics class, which manages a graphics
context, and provides a set of device-independent methods for drawing texts, figures
and images on the screen on different platforms.
Graphics Class' Drawing Methods

■ The Graphics class provides methods for drawing three types of graphical objects:

■ Text strings: via the drawString() method. Take note that System.out.println() prints to
the system console, not to the graphics screen.
■ Vector-graphic primitives and shapes: via methods drawXxx() and fillXxx(), where Xxx
could be Line, Rect, Oval, Arc, PolyLine, RoundRect, or 3DRect.
■ Bitmap images: via the drawImage() method.
Draw String

■ / Drawing (or printing) texts on the graphics screen:


■ drawString(String str, int xBaselineLeft, int yBaselineLeft);
Drawling line

■ // Drawing lines:
drawLine(int x1, int y1, int x2, int y2);
drawPolyline(int[] xPoints, int[] yPoints, int numPoint);
Drawing primitive shape

■ // Drawing primitive shapes:


■ drawRect(int xTopLeft, int yTopLeft, int width, int height);
■ drawOval(int xTopLeft, int yTopLeft, int width, int height);
■ drawArc(int xTopLeft, int yTopLeft, int width, int height, int startAngle, int arcAngle);
■ draw3DRect(int xTopLeft, int, yTopLeft, int width, int height, boolean raised);
■ drawRoundRect(int xTopLeft, int yTopLeft, int width, int height, int arcWidth, int
arcHeight)
■ drawPolygon(int[] xPoints, int[] yPoints, int numPoint);
Filling primitive shapes

■ / Filling primitive shapes:


■ fillRect(int xTopLeft, int yTopLeft, int width, int height);
■ fillOval(int xTopLeft, int yTopLeft, int width, int height);
■ fillArc(int xTopLeft, int yTopLeft, int width, int height, int startAngle, int arcAngle);
■ fill3DRect(int xTopLeft, int, yTopLeft, int width, int height, boolean raised);
■ fillRoundRect(int xTopLeft, int yTopLeft, int width, int height, int arcWidth, int arcHeight)
■ fillPolygon(int[] xPoints, int[] yPoints, int numPoint);

Drawing or displaying images

■ drawImage(Image img, int xTopLeft, int yTopLeft, ImageObserver obs); // draw image
with its size
■ drawImage(Image img, int xTopLeft, int yTopLeft, int width, int height, ImageObserver
o); // resize image on screen

You might also like