SlideShare a Scribd company logo
1 of 30
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)

Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Applets
AppletsApplets
Applets
 
Java Beans
Java BeansJava Beans
Java Beans
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
 
Files in java
Files in javaFiles in java
Files in java
 
Exception handling in ASP .NET
Exception handling in ASP .NETException handling in ASP .NET
Exception handling in ASP .NET
 
Applets in java
Applets in javaApplets in java
Applets in java
 
OOP java
OOP javaOOP java
OOP java
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Java beans
Java beansJava beans
Java beans
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithm
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Java swing
Java swingJava swing
Java swing
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Interface in java
Interface in javaInterface in java
Interface in java
 

Similar to graphics programming in java

Basic Graphics in Java
Basic Graphics in JavaBasic Graphics in Java
Basic Graphics in JavaPrakash Kumar
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Philip Schwarz
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bPhilip Schwarz
 
Displaying information within a window.68
Displaying information within a window.68Displaying information within a window.68
Displaying information within a window.68myrajendra
 
2D & 3D Modelling with Mathematica
2D & 3D Modelling with Mathematica2D & 3D Modelling with Mathematica
2D & 3D Modelling with MathematicaMiles Ford
 
BS LAB Manual (1).pdf
BS LAB Manual  (1).pdfBS LAB Manual  (1).pdf
BS LAB Manual (1).pdfssuser476810
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programmingsrijavel
 
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaSierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaPhilip Schwarz
 
IRJET - Application of Linear Algebra in Machine Learning
IRJET -  	  Application of Linear Algebra in Machine LearningIRJET -  	  Application of Linear Algebra in Machine Learning
IRJET - Application of Linear Algebra in Machine LearningIRJET Journal
 
PLOTTING UNITE STEP AND RAMP FUNCTION IN MATLAB
PLOTTING UNITE STEP AND RAMP  FUNCTION  IN  MATLAB PLOTTING UNITE STEP AND RAMP  FUNCTION  IN  MATLAB
PLOTTING UNITE STEP AND RAMP FUNCTION IN MATLAB Mahmudul Hasan
 
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Amairullah Khan Lodhi
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Appletbackdoor
 

Similar to graphics programming in java (20)

Lecture3 oopj
Lecture3 oopjLecture3 oopj
Lecture3 oopj
 
Session4 applets
Session4   appletsSession4   applets
Session4 applets
 
Basic Graphics in Java
Basic Graphics in JavaBasic Graphics in Java
Basic Graphics in Java
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
 
Displaying information within a window.68
Displaying information within a window.68Displaying information within a window.68
Displaying information within a window.68
 
2D & 3D Modelling with Mathematica
2D & 3D Modelling with Mathematica2D & 3D Modelling with Mathematica
2D & 3D Modelling with Mathematica
 
unit3.3.pptx
unit3.3.pptxunit3.3.pptx
unit3.3.pptx
 
BS LAB Manual (1).pdf
BS LAB Manual  (1).pdfBS LAB Manual  (1).pdf
BS LAB Manual (1).pdf
 
13slide graphics
13slide graphics13slide graphics
13slide graphics
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaSierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
 
IRJET - Application of Linear Algebra in Machine Learning
IRJET -  	  Application of Linear Algebra in Machine LearningIRJET -  	  Application of Linear Algebra in Machine Learning
IRJET - Application of Linear Algebra in Machine Learning
 
Applet in java
Applet in javaApplet in java
Applet in java
 
PLOTTING UNITE STEP AND RAMP FUNCTION IN MATLAB
PLOTTING UNITE STEP AND RAMP  FUNCTION  IN  MATLAB PLOTTING UNITE STEP AND RAMP  FUNCTION  IN  MATLAB
PLOTTING UNITE STEP AND RAMP FUNCTION IN MATLAB
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
 

More from Abinaya B

Overview of bigdata
Overview of bigdataOverview of bigdata
Overview of bigdataAbinaya B
 
exception handling in java
exception handling in javaexception handling in java
exception handling in javaAbinaya B
 
data structures
data structuresdata structures
data structuresAbinaya B
 
data structures- back tracking
data structures- back trackingdata structures- back tracking
data structures- back trackingAbinaya B
 
exception handling in java
exception handling in javaexception handling in java
exception handling in javaAbinaya B
 
digital image processing
digital image processingdigital image processing
digital image processingAbinaya B
 
Image filtering in Digital image processing
Image filtering in Digital image processingImage filtering in Digital image processing
Image filtering in Digital image processingAbinaya B
 
software engineering
software engineeringsoftware engineering
software engineeringAbinaya B
 
software cost factor
software cost factorsoftware cost factor
software cost factorAbinaya B
 
Basic topic on os
Basic topic on osBasic topic on os
Basic topic on osAbinaya B
 
Digital principles basic
Digital principles basicDigital principles basic
Digital principles basicAbinaya B
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in CAbinaya B
 
Introduction to 80386
Introduction to 80386Introduction to 80386
Introduction to 80386Abinaya B
 
Network standardization
Network standardizationNetwork standardization
Network standardizationAbinaya B
 

More from Abinaya B (18)

Multimedia
MultimediaMultimedia
Multimedia
 
Overview of bigdata
Overview of bigdataOverview of bigdata
Overview of bigdata
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
 
data structures
data structuresdata structures
data structures
 
data structures- back tracking
data structures- back trackingdata structures- back tracking
data structures- back tracking
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
 
digital image processing
digital image processingdigital image processing
digital image processing
 
Image filtering in Digital image processing
Image filtering in Digital image processingImage filtering in Digital image processing
Image filtering in Digital image processing
 
software engineering
software engineeringsoftware engineering
software engineering
 
software cost factor
software cost factorsoftware cost factor
software cost factor
 
Data Mining
Data MiningData Mining
Data Mining
 
Datamining
DataminingDatamining
Datamining
 
Basic topic on os
Basic topic on osBasic topic on os
Basic topic on os
 
Digital principles basic
Digital principles basicDigital principles basic
Digital principles basic
 
Rdbms1
Rdbms1Rdbms1
Rdbms1
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
 
Introduction to 80386
Introduction to 80386Introduction to 80386
Introduction to 80386
 
Network standardization
Network standardizationNetwork standardization
Network standardization
 

Recently uploaded

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 

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