SlideShare a Scribd company logo
JAVA
GRAPHICS PROGRAMMING
B.ABINAYA BHARATHI M.Sc[Cs&IT],
NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE,
THENI.
1
INTRODUCTION
 Main feature in java is creating a graphical interface .
 Graphics in any language gives a wonderful look and feel to
the users .
 Two packages that are mainly used to draw graphics.
 Applet package
 awt package
2
APPLET
 An applet is a Java program that runs in a Web browser
 An applet is a Java class that extends the java.applet.Applet
class
 A main() method is not invoked on an applet
 Applets are designed to be embedded within an HTML page.
3
EXAMPLE APPLET PROGRAM
Importing applet package
` This html code tells the compiled java
applet of a sample.class
Paint method is used to paint
a applet
drawstring( ) - graphics class
displays the string within the
double quotes 4
OUTPUT
5
AWT PACKAGE
 The Abstract Window Toolkit (AWT)
 It is Java's original platform-independent windowing,
graphics, and user-interface toolkit.
 The AWT classes are contained in the java.awt package.
 It is used to create a interactive page with buttons , text box
and other tools .
6
GRAPHICS CLASS
 Graphics class include methods for drawing shapes , images
to the screen inside your applet
 Graphics class contain several inbuilt methods to create
graphical interface.
7
DRAWING STRING IN APPLET
drawString()
 drawString() is used to display string in Graphical area.
SYNTAX
drawString(String str, int x, int y)
 String to be displayed
 x and y position on the graphical window.
8
DRAWING LINES
drawLine()
 This method is used to draw a line.
SYNTAX
drawLine(int x1, int y1, int x2, int y2)
 This method contains two pair of coordinates, (x1, y1) and
(x2, y2) as arguments
 draws a line between them.
9
drawPolyline()
 It connects the xPoints and yPoints arrays
 It does not connect the endpoints.
SYNTAX
drawPolyline(int[] xPoints,int[] yPoints,int nPoints)
10
SAMPLE CODE
11
OUTPUT
12
DRAWING SHAPE PRIMITIVES
drawRect()
 Used to draw rectangle shape in an applet.
SYNTAX
drawRect(int xTopLeft, int yTopLeft, int width, int height);
 First two points represents x and y coordinates of the top
left corner
 Next two represent the width and the height of the
rectangle. 13
drawOval()
 Used to draw circle and oval in an applet.
SYNTAX
drawOval(int xTopLeft, int yTopLeft, int width, int height);
 First two arguments represents x and y coordinates of the
top left .
 Third and fourth argument represent the width and
the height of the rectangle .
14
drawArc()
 Arc is same as oval
 first four are same as arguments of drawOval( )
 Next arguments represents starting angle and degrees
around the arc.
SYNTAX
drawArc(int xTopLeft, int yTopLeft, int width, int height, int
startAngle, int arcAngle);
15
drawRoundRect()
 By using this method we can draw rounded rectangle
SYNTAX
drawRoundRect(int xTopLeft, int yTopLeft, int width, int
height, int arcWidth, int arcHeight)
 Rounded rectangle contains same argument as drawRect().
 In rounded rectangle two extra arguments representing the
width and height of the angle of corners.
16
drawPolygon()
 This method Draws an outline polygon as per the
coordinates specified in the x[] and y[] arrays
 Numpoints - number of elements in the array
SYNTAX
drawPolygon(int[] xPoints, int[] yPoints, int numPoint);
17
SAMPLE CODE
18
OUTPUT
19
FILLING PRIMITIVE SHAPES
fillOval()
 The fillOval() method draws a filled oval .
 We can’t specify the oval's center point and radii.
 The filled oval is one pixel smaller to the right and bottom
than requested.
SYNTAX
fillOval(int xTopLeft, int yTopLeft, int width, int height);
20
fillArc()
 The fillArc() method is similar to the drawArc() method
except that it draws a filled arc .
 If width and height are equal and arcAngle is 360 degrees
 fillArc() draws a filled circle.
SYNTAX
fillArc(int xTopLeft, int yTopLeft, int width, int height, int
startAngle, int arcAngle);
21
fillRect()
 fillRect() method draws a filled .
 The filled rectangle is one pixel smaller to the right and
bottom than requested.
 If width or height is negative, nothing is drawn.
SYNTAX
fillRect(int xTopLeft, int yTopLeft, int width, int height);
22
fillPolygon()
 The fillPolygon() method draws a polygon.
 If xPoints or yPoints does not have numPoints elements, it
throws the run-time exception
andIllegalArgumentException.
 If the polygon is not closed, fillPolygon() adds a segment
connecting the endpoints.
SYNTAX
fillPolygon(int[] xPoints, int[] yPoints, int numPoint);

23
fillRoundRect()
 The fillRoundRect() method is similar to
drawRoundRect() method except that it draws a filled
rectangle on the drawing area
 If width, height, arcWidth, and arcHeight are all equal, you
get a filled circle.
SYNTAX
fillRoundRect(int xTopLeft, int yTopLeft, int width, int
height, int arcWidth, int arcHeight);
24
SAMPLE CODE
25
OUTPUT
26
setColor( )
 AWT color class used to specify any color we need.
 color is specified as Color.Blue
 By default, graphics objects are drawn in the current
foreground color.
 We can change this color by calling the setColor( ).
EX:
g.setColor(Color . yellow);
27
SAMPLE CODE
28
OUTPUT
29
THANK YOU
30

More Related Content

What's hot (20)

PPTX
Applets in java
Wani Zahoor
 
PPTX
Packages in java
Elizabeth alexander
 
PPTX
Java Server Pages(jsp)
Manisha Keim
 
PPTX
JAVA AWT
shanmuga rajan
 
PDF
Applets
Prabhakaran V M
 
PPTX
HTML Forms
Ravinder Kamboj
 
PPTX
Interface in java
PhD Research Scholar
 
PPTX
Network programming in java - PPT
kamal kotecha
 
PPT
Ch 3 event driven programming
Chaffey College
 
PPT
CSS Basics
WordPress Memphis
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
Web forms in ASP.net
Madhuri Kavade
 
PDF
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
PDF
jQuery for beginners
Arulmurugan Rajaraman
 
PPT
Visual Studio IDE
Sayantan Sur
 
PPT
javaScript.ppt
sentayehu
 
PPTX
Threads in JAVA
Haldia Institute of Technology
 
PPTX
Javascript operators
Mohit Rana
 
PPTX
Dda algorithm
Mani Kanth
 
Applets in java
Wani Zahoor
 
Packages in java
Elizabeth alexander
 
Java Server Pages(jsp)
Manisha Keim
 
JAVA AWT
shanmuga rajan
 
HTML Forms
Ravinder Kamboj
 
Interface in java
PhD Research Scholar
 
Network programming in java - PPT
kamal kotecha
 
Ch 3 event driven programming
Chaffey College
 
CSS Basics
WordPress Memphis
 
Classes, objects in JAVA
Abhilash Nair
 
Web forms in ASP.net
Madhuri Kavade
 
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
jQuery for beginners
Arulmurugan Rajaraman
 
Visual Studio IDE
Sayantan Sur
 
javaScript.ppt
sentayehu
 
Javascript operators
Mohit Rana
 
Dda algorithm
Mani Kanth
 

Similar to graphics programming in java (20)

PPT
Client Side Programming with Applet
backdoor
 
PPTX
Basic Graphics in Java
Prakash Kumar
 
PPT
13slide graphics
Dorothea Chaffin
 
PDF
Lec 7 28_aug [compatibility mode]
Palak Sanghani
 
PPT
Displaying information within a window.68
myrajendra
 
PPT
Unit 2 Graphics and awt.hsjshbshshsbsbsbs.pptx
wwwe51162
 
PPT
Introduction to Java Applet and Life cycle of an Applet
muthulakshmi279332
 
DOCX
Lecture3 oopj
Dhairya Joshi
 
PDF
Lec 11 12_sept [compatibility mode]
Palak Sanghani
 
PPTX
Applet and graphics programming
srijavel
 
PPT
ch03g-graphics.ppt
Mahyuddin8
 
PPT
Applets - lev' 2
Rakesh T
 
PPT
first-applet
Mohit Patodia
 
PPT
Java Graphics
Shraddha
 
PDF
Applets
Ravi Kant Sahu
 
PDF
Unit 5 Java Programming with Linux-converted.pdf
ranjithunni35
 
PPT
Session11 J2ME MID-Low Level User Interface(LLUI)-graphics
muthusvm
 
PPT
Session4 applets
Unit Nexus Pvt. Ltd.
 
Client Side Programming with Applet
backdoor
 
Basic Graphics in Java
Prakash Kumar
 
13slide graphics
Dorothea Chaffin
 
Lec 7 28_aug [compatibility mode]
Palak Sanghani
 
Displaying information within a window.68
myrajendra
 
Unit 2 Graphics and awt.hsjshbshshsbsbsbs.pptx
wwwe51162
 
Introduction to Java Applet and Life cycle of an Applet
muthulakshmi279332
 
Lecture3 oopj
Dhairya Joshi
 
Lec 11 12_sept [compatibility mode]
Palak Sanghani
 
Applet and graphics programming
srijavel
 
ch03g-graphics.ppt
Mahyuddin8
 
Applets - lev' 2
Rakesh T
 
first-applet
Mohit Patodia
 
Java Graphics
Shraddha
 
Unit 5 Java Programming with Linux-converted.pdf
ranjithunni35
 
Session11 J2ME MID-Low Level User Interface(LLUI)-graphics
muthusvm
 
Session4 applets
Unit Nexus Pvt. Ltd.
 
Ad

More from Abinaya B (18)

PPTX
Multimedia
Abinaya B
 
PPTX
Overview of bigdata
Abinaya B
 
PPTX
exception handling in java
Abinaya B
 
PPTX
data structures
Abinaya B
 
PPTX
data structures- back tracking
Abinaya B
 
PPTX
exception handling in java
Abinaya B
 
PPTX
digital image processing
Abinaya B
 
PPTX
Image filtering in Digital image processing
Abinaya B
 
PPTX
software engineering
Abinaya B
 
PPTX
software cost factor
Abinaya B
 
PPTX
Data Mining
Abinaya B
 
PPTX
Datamining
Abinaya B
 
PPTX
Basic topic on os
Abinaya B
 
PPTX
Digital principles basic
Abinaya B
 
PPTX
Rdbms1
Abinaya B
 
PPTX
Managing I/O & String function in C
Abinaya B
 
PPTX
Introduction to 80386
Abinaya B
 
PPTX
Network standardization
Abinaya B
 
Multimedia
Abinaya B
 
Overview of bigdata
Abinaya B
 
exception handling in java
Abinaya B
 
data structures
Abinaya B
 
data structures- back tracking
Abinaya B
 
exception handling in java
Abinaya B
 
digital image processing
Abinaya B
 
Image filtering in Digital image processing
Abinaya B
 
software engineering
Abinaya B
 
software cost factor
Abinaya B
 
Data Mining
Abinaya B
 
Datamining
Abinaya B
 
Basic topic on os
Abinaya B
 
Digital principles basic
Abinaya B
 
Rdbms1
Abinaya B
 
Managing I/O & String function in C
Abinaya B
 
Introduction to 80386
Abinaya B
 
Network standardization
Abinaya B
 
Ad

Recently uploaded (20)

PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
community health nursing question paper 2.pdf
Prince kumar
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 

graphics programming in java

  • 1. JAVA GRAPHICS PROGRAMMING B.ABINAYA BHARATHI M.Sc[Cs&IT], NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE, THENI. 1
  • 2. INTRODUCTION  Main feature in java is creating a graphical interface .  Graphics in any language gives a wonderful look and feel to the users .  Two packages that are mainly used to draw graphics.  Applet package  awt package 2
  • 3. APPLET  An applet is a Java program that runs in a Web browser  An applet is a Java class that extends the java.applet.Applet class  A main() method is not invoked on an applet  Applets are designed to be embedded within an HTML page. 3
  • 4. EXAMPLE APPLET PROGRAM Importing applet package ` This html code tells the compiled java applet of a sample.class Paint method is used to paint a applet drawstring( ) - graphics class displays the string within the double quotes 4
  • 6. AWT PACKAGE  The Abstract Window Toolkit (AWT)  It is Java's original platform-independent windowing, graphics, and user-interface toolkit.  The AWT classes are contained in the java.awt package.  It is used to create a interactive page with buttons , text box and other tools . 6
  • 7. GRAPHICS CLASS  Graphics class include methods for drawing shapes , images to the screen inside your applet  Graphics class contain several inbuilt methods to create graphical interface. 7
  • 8. DRAWING STRING IN APPLET drawString()  drawString() is used to display string in Graphical area. SYNTAX drawString(String str, int x, int y)  String to be displayed  x and y position on the graphical window. 8
  • 9. DRAWING LINES drawLine()  This method is used to draw a line. SYNTAX drawLine(int x1, int y1, int x2, int y2)  This method contains two pair of coordinates, (x1, y1) and (x2, y2) as arguments  draws a line between them. 9
  • 10. drawPolyline()  It connects the xPoints and yPoints arrays  It does not connect the endpoints. SYNTAX drawPolyline(int[] xPoints,int[] yPoints,int nPoints) 10
  • 13. DRAWING SHAPE PRIMITIVES drawRect()  Used to draw rectangle shape in an applet. SYNTAX drawRect(int xTopLeft, int yTopLeft, int width, int height);  First two points represents x and y coordinates of the top left corner  Next two represent the width and the height of the rectangle. 13
  • 14. drawOval()  Used to draw circle and oval in an applet. SYNTAX drawOval(int xTopLeft, int yTopLeft, int width, int height);  First two arguments represents x and y coordinates of the top left .  Third and fourth argument represent the width and the height of the rectangle . 14
  • 15. drawArc()  Arc is same as oval  first four are same as arguments of drawOval( )  Next arguments represents starting angle and degrees around the arc. SYNTAX drawArc(int xTopLeft, int yTopLeft, int width, int height, int startAngle, int arcAngle); 15
  • 16. drawRoundRect()  By using this method we can draw rounded rectangle SYNTAX drawRoundRect(int xTopLeft, int yTopLeft, int width, int height, int arcWidth, int arcHeight)  Rounded rectangle contains same argument as drawRect().  In rounded rectangle two extra arguments representing the width and height of the angle of corners. 16
  • 17. drawPolygon()  This method Draws an outline polygon as per the coordinates specified in the x[] and y[] arrays  Numpoints - number of elements in the array SYNTAX drawPolygon(int[] xPoints, int[] yPoints, int numPoint); 17
  • 20. FILLING PRIMITIVE SHAPES fillOval()  The fillOval() method draws a filled oval .  We can’t specify the oval's center point and radii.  The filled oval is one pixel smaller to the right and bottom than requested. SYNTAX fillOval(int xTopLeft, int yTopLeft, int width, int height); 20
  • 21. fillArc()  The fillArc() method is similar to the drawArc() method except that it draws a filled arc .  If width and height are equal and arcAngle is 360 degrees  fillArc() draws a filled circle. SYNTAX fillArc(int xTopLeft, int yTopLeft, int width, int height, int startAngle, int arcAngle); 21
  • 22. fillRect()  fillRect() method draws a filled .  The filled rectangle is one pixel smaller to the right and bottom than requested.  If width or height is negative, nothing is drawn. SYNTAX fillRect(int xTopLeft, int yTopLeft, int width, int height); 22
  • 23. fillPolygon()  The fillPolygon() method draws a polygon.  If xPoints or yPoints does not have numPoints elements, it throws the run-time exception andIllegalArgumentException.  If the polygon is not closed, fillPolygon() adds a segment connecting the endpoints. SYNTAX fillPolygon(int[] xPoints, int[] yPoints, int numPoint);  23
  • 24. fillRoundRect()  The fillRoundRect() method is similar to drawRoundRect() method except that it draws a filled rectangle on the drawing area  If width, height, arcWidth, and arcHeight are all equal, you get a filled circle. SYNTAX fillRoundRect(int xTopLeft, int yTopLeft, int width, int height, int arcWidth, int arcHeight); 24
  • 27. setColor( )  AWT color class used to specify any color we need.  color is specified as Color.Blue  By default, graphics objects are drawn in the current foreground color.  We can change this color by calling the setColor( ). EX: g.setColor(Color . yellow); 27