AWT Graphics in Java

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.AWT Graphics in Java

Java Graphics Draw Hut Man

Following is a good program giving command over graphics. First imagine rough coordinates, after seeing the figure, adjust the coordinates. import java.awt.* ; import java.awt.event.* ; public class Hut extends Frame { public Hut() { setBackground(Color.cyan); setTitle(“House to live by SNRao”); setSize(450,350); setVisible(true); addWindowListener(new WindowAdapter() { // for frame closing public void windowClosing( WindowEvent e …

Java Graphics Draw Hut Man Read More »

Java Draw Rectangle Applet graphics

Java supports graphics through applications (extends Frame) and applets (extending Applet). We have seen drawing rectangles through applications and now let us convert the same rectangle application into an applet program. To go throug this code, it is required to have the knowledge of applets, applet life cycle methods and drawing strings on applet window. …

Java Draw Rectangle Applet graphics Read More »

Java Graphics Geometrical Figures

Java Graphics Geometrical Figures Check out, your one-stop destination for all Java Geometrical Figures. Java Graphics coordinate Structure: Graphics – Introduction. Drawing Figures both Outline and Filled: Lines, Strings with colors and fonts, Right-angled rectangles, Round-cornered rectangles, 3-D Rectangles, Ovals, Arcs, Polygons. Array Drawing: Complete and partial array elements. Special Affects: Drawing thicker lines, Drawing …

Java Graphics Geometrical Figures Read More »

Java Graphics Draw Arcs

A segment of an oval is an arc. The arc angle can be positive (sweeps anti-clockwise) or negative (sweeps clockwise). As with other figures, the arcs can be outline or solid. Supporting methods from java.awt.Graphics class void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): draws an outline arc. void fillArc(int …

Java Graphics Draw Arcs Read More »

Java Draw Ovals

Java Draw Ovals Summary: In this tutorial "Java Draw Ovals", you learn drawing of drawing ovals in Java graphics. After learning rectangles drawing, let us see the oval. Oval (Latin: Ovum meaning egg) is an elliptical shape rounded at both ends. Supporting methods from java.awt.Graphics class void drawOval(int x, int y, int width, int height); …

Java Draw Ovals Read More »

Java Draw Round Cornered Rectangles

Drawing Rectangles Java graphics supports 3 types drawing rectangles. 1. Right-angled rectangles 2. Round-cornered rectangles 3. 3-D Rectangles Java requires width and height of the rectangle and x and y coordinates where rectangle is be drawn. Java does not include a special method, something like drawSquare(), to draw a square. Square can be drawn with …

Java Draw Round Cornered Rectangles Read More »

Java Draw Rectangles

Java Draw Rectangles Summary: In this tutorial "Java Draw Rectangles", you learn how much it is easy to draw rectangles in Java. Drawing Rectangles 3 types of rectangles Java supports Right-angled rectangles Round-cornered rectangles 3-D Rectangles Java requires width and height of the rectangle and x and y coordinates where rectangle (top left corner position) …

Java Draw Rectangles Read More »

Java AWT Drawing Strings Frame

Graphics class allows us to draw strings on the frame with its method drawString(). Following is the signature. void drawString(String str1, int x, int y): x and y are the coordinates where the string str1 is to be drawn on the frame. Following program illustrates. import java.awt.*; public class StringsDrawing extends Frame { public StringsDrawing() …

Java AWT Drawing Strings Frame Read More »

Java Graphics Draw Lines

Java Graphics Draw Lines Summary: By the end of this tutorial "Java Graphics Draw Lines", you will come to know the drawing of lines on frame. Drawing graphics is very simple in Java. The line drawing takes four parameters of starting point x and y coordinates and ending point x and y coordinates. Supporting method …

Java Graphics Draw Lines Read More »

Java Centered Text with Underline

This code gives strength on AWT graphics programming. There are no predefined methods that can be used straightaway to place the text in the center of the frame and also underline the text. Some programming techniques are required to solve the task. Example on Java Centered Text with Underline The following program places the sting …

Java Centered Text with Underline Read More »

Java Draw Cylinder Cube Circle

There are no predefined methods to draw a cylinder, cube and circle. Using existing methods of Graphics class like drawOval(), drawRect(), drawArc() etc., the task can be done. import java.awt.*; import java.awt.event.*; public class SpecialFigures extends Frame { public SpecialFigures() { setTitle(“Special Effects”); setSize(450,550); setVisible(true); } public void paint(Graphics g) { // to draw a …

Java Draw Cylinder Cube Circle Read More »

Java Graphics Tutorial

Java Graphics Tutorial Summary: In this tutorial "Java Graphics Tutorial", you will come to know of Java graphics concepts like frame and its coordinate system, Graphics class etc. This understanding is very necessary for future programs. The term Graphics is derived from the Latin word Graphicus. Graphics involves drawing various geometrical figures like rectangles, polygons, …

Java Graphics Tutorial Read More »

Java Draw Images Graphics

Java Draw Images Graphics Summary: Java permits to draw images in graphics. Explained in this tutorial "Java Draw Images Graphics" in simple terms, code and screenshot. Go through. To draw images, the Graphics class includes a method drawImage(). Drawing images requires special coding using ImageObserver. 2. Drawing Images in Applications (Frames) After seeing how to …

Java Draw Images Graphics Read More »

Java Retrieve Color Information

Java Retrieve Color Information Summary: Apart using colors in graphics, you can retrieve the information of the components of Color object. Comfortable to read in simple terms in "Java Retrieve Color Information". We have learnt about Color class, how to create Color objects both RGB and HSB models and the predefined colors Java supports. Now …

Java Retrieve Color Information Read More »

Java Clear Copy Graphics Area

java.awt.Graphics class comes with many methods of drawing and also with some non-drawing methods that will support drawing indirectly. These methods include clearRect() and copyArea() etc. clearRect() clears a part of graphical area where a drawing may exist with its own background. When cleared, the cleared area shows the background area of the frame (a …

Java Clear Copy Graphics Area Read More »

Java Graphics Draw Polygons Applets

A polygon is a closed figure with many lines joined one to another. The ending point of one line is the starting point to another line and finally the last point is joins with the first point. java.awt.Graphics class comes with two methods and one constructor to draw polygons. void drawPolygon(int x[], int y[], int …

Java Graphics Draw Polygons Applets Read More »