SlideShare une entreprise Scribd logo
1  sur  52
From :
Shraddha Sheth
Chapter-19
Drawing in a Window
 The coordinate system used by a container to
position components within it is analogous to the
screen coordinate system.
 The origin is at the top-left corner of the container,
with the positive x-axis running horizontally from
left to right, and the positive y-axis running from
top to bottom.
 The positions of buttons in a JWindow or a JFrame
object are specified as a pair of (x, y) pixel
coordinates, relative to the origin at the top-left
corner of the container object on the screen.
The Coordinate System
Cont..
The content pane will have its own coordinate
system, too, which will be used to position the
components that it contains.
Every component has its own coordinate system,
which will be used to position the component that it
contains.
Cont..
You also need a coordinate system to draw on a
component—to draw a line, for example, you need to
be able to specify where it begins and ends in relation
to the component
Drawing on a Component
Device-independent logical coordinate system is
called the user coordinate system or user space.
 By default, this coordinate system has the same
orientation as the system for positioning components
in containers.
The origin is at the top-left corner; the positive x-axis
runs
from left to right, and the positive y-axis from top to
bottom.
Coordinates are usually specified as floating- point
values, although you can also use integers.
Cont..
A particular graphical output device will have its own
device coordinate system
This coordinate system has the same orientation as
the default user coordinate system, but the coordinate
units depend on the characteristics of the device.
Cont..
With the default mapping from user coordinates to
device coordinates, the units for user coordinates are
assumed to be 1/72 of an inch. Since for most screen
devices the pixels are approximately 1/72 inch apart,
the conversion amounts to an identity
transformation.
Graphics Contexts
The user coordinate system for drawing on a
component using Java 2D is encapsulated in an object
of type Graphics2D, which is usually referred to as a
graphics context. It provides all the tools you need
to draw whatever you want on the surface of the
component. A graphics context enables you to draw
lines, curves, shapes, filled shapes, as well as images,
and gives you a great deal of control over the drawing
process.
Cont..
The information required for converting user
coordinates to device coordinates is encapsulated in
three different kinds of objects:
❑ A GraphicsEnvironment object encapsulates all
the graphics devices (as GraphicsDevice objects) and
fonts (as Font objects) that are available on your
computer.
❑ A GraphicsDevice object encapsulates information
about a particular device, such as a screen or a
printer, and stores it in one or more
GraphicsConfiguration objects.
❑ A GraphicsConfiguration object defines the
characteristics of a particular device, such as a screen
or a printer.
Cont..
We can draw on a component by implementing the
paint() method that is called whenever the
component needs to be reconstructed.
The another way of drawing on a component is by
obtaining a graphics context for a component at any
time just by calling its getGraphics() method and then
using methods for the Graphics object to specify the
drawing operations.
If you don’t want to call paint() method directly in
some occasion , you have to use repaint() method.
An Example,
public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D)g;
// Get a Java 2D device context
g2D.setPaint(Color.RED); // Draw in red
g2D.draw3DRect(50, 50, 150, 100, true);
// Draw a raised 3D rectangle
g2D.drawString(“A nice 3D rectangle”, 60,
100); // Draw some text
}
The Drawing Process
 A Graphics2D object maintains a whole heap of
information that determines how things are drawn.
Most of this information is contained in six
attributes within a Graphics2D object:
1. Paint
2. Stroke
3. Font
4. Transform
5. Clip
6. Composite
Rendering Objects
Shapes
Classes that define geometric shapes are contained in
the java.awt.geom package, but the Shape interface
that these classes implement is defined in java.awt.
To draw a shape on a component, you just need to
pass the object defining the shape to the draw()
method for the Graphics2D object for the component.
Classes Defining Points
Two classes in the java.awt.geom package define
points, Point2D.Float and Point2D.Double.
Cont..
The operations that each of the three concrete point
classes inherits are:
Accessing coordinate values
Calculating the distance between two points
Cont..
OR
Comparing points—The equals() method compares
the current point with the point object referenced by
the argument and returns true if they are equal and
false otherwise.
Cont..
Setting a new location for a point : setLocation()
method is used to set the location of the point.
Lines and Rectangles
Drawing a Line
OR
You draw a line using the draw() method for a Graphics2D object
Create a Rectangle
getx() and gety() are used to retrieve the coordinates
of rectangle.
Getheight() and getwidth() returns the height and
width.
You can set the position, width, and height of a
rectangle by calling its setRect() method.
Round Rectangle
Combining Rectangles
Filling Objects
Once you know how to create and draw a shape,
filling it is easy. You just call the fill() method for the
Graphics2D object and pass a reference of type Shape
to it.
 This works for any shape but for sensible results the
boundary should be closed.
 The way the enclosed region will be filled is
determined by the window rule in effect for the
shape.
Ex., Filling Star
public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D)g;
Star star = new Star(0,0); // Create a star
float delta = 60; // Increment between stars
float starty = 0; // Starting y position
// Draw 3 rows of 4 stars
for(int yCount = 0 ; yCount<3; yCount++) {
starty += delta; // Increment row position
float startx = 0; // Start x position in a row
// Draw a row of 4 stars
for(int xCount = 0 ; xCount<4; xCount++) {
g2D.setPaint(Color.BLUE); // Drawing color blue
g2D.draw(star.atLocation(startx += delta, starty));
g2D.setPaint(Color.GREEN); // Color for fill is green
g2D.fill(star.getShape()); // Fill the star
}
}
}
Gradient Fill
Cont..
From :
Shraddha Sheth
Chapter-20
Extending the GUI
Using Dialogs
A dialog is a window that is displayed within the
context of another window—its parent.
The JDialog class in the javax.swing package defines
dialogs, and a JDialog object is a specialized sort of
Window.
A JDialog object will typically contain one or more
components for displaying information or allowing
data to be entered, plus buttons for selection of dialog
options (including closing the dialog) together.
Modal and Non-Modal Dialogs
There are two different kinds of dialog that you can
create, and they have distinct operating
characteristics.
You have a choice of creating either a modal dialog
or a non-modal dialog.
When you display a modal dialog—typically by
selecting a menu item or clicking a button—it inhibits
the operation of any other windows in the application
until you close the dialog.
Cont..
A non-modal dialog can be left on the screen for as long
as you want, since it doesn’t block interaction with
other windows in the application.
You can also switch the focus back and forth between
using a non-modal dialog and using any other
application windows that are on the screen.
Example
Instant Dialogs
The JOptionPane class in the javax.swing package
defines a number of static methods that will create
and display standard modal dialogs for you.
The following static methods in the JOptionPane class
produce message dialogs:
You can refer to various methos of this from our
textbook on page no-1009.
Input Dialogs
JOptionPane also has four static methods that you can use to
create standard modal input dialogs:
showInputDialog(Object message)
eg,
String input = JOptionPane.showInputDialog(“Enter
Input:”);
Cont..
String input = JOptionPane.showInputDialog(null,
“Enter Input:”,“Dialog for Input”,
JOptionPane.WARNING_MESSAGE);
Cont..
String[] choices = {“Money”, “Health”, “Happiness”,
“This”, “That”, “The Other”};
String input =
(String)JOptionPane.showInputDialog(null, “Choose
now...”, “The Choice of a Lifetime”,
JOptionPane.QUESTION_MESSAGE,
null, // Use default icon
choices, // Array of choices
choices[1]); // Initial choice
Choosing a Custom Color
Facility of Choosing Custom Color is provided by the
javax.swing.JColorChooser class.
Example
Thank You..

Contenu connexe

Tendances

Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualAnkit Kumar
 
Java applet handouts
Java applet handoutsJava applet handouts
Java applet handoutsiamkim
 
How to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabHow to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabScilab
 
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
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16HUST
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09HUST
 
Matlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge DetectionMatlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge DetectionDataminingTools Inc
 
C++: inheritance, composition, polymorphism
C++: inheritance, composition, polymorphismC++: inheritance, composition, polymorphism
C++: inheritance, composition, polymorphismJussi Pohjolainen
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsRai University
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletraksharao
 

Tendances (20)

Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Awt components
Awt componentsAwt components
Awt components
 
Bai 1
Bai 1Bai 1
Bai 1
 
Intake 38 6
Intake 38 6Intake 38 6
Intake 38 6
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Applications
ApplicationsApplications
Applications
 
Java applet handouts
Java applet handoutsJava applet handouts
Java applet handouts
 
How to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabHow to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in Scilab
 
For ICT - PPT
For ICT - PPTFor ICT - PPT
For ICT - PPT
 
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
 
Templates
TemplatesTemplates
Templates
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09
 
Matlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge DetectionMatlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge Detection
 
Ai Test
Ai TestAi Test
Ai Test
 
C++: inheritance, composition, polymorphism
C++: inheritance, composition, polymorphismC++: inheritance, composition, polymorphism
C++: inheritance, composition, polymorphism
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
Cad 003
Cad 003Cad 003
Cad 003
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of applet
 

Similaire à Java Graphics

Autocad civil project file
Autocad civil project fileAutocad civil project file
Autocad civil project filenaveen899
 
Graphics software
Graphics softwareGraphics software
Graphics softwareMohd Arif
 
RS and GIS TW- 1&2.pdf
RS and GIS TW- 1&2.pdfRS and GIS TW- 1&2.pdf
RS and GIS TW- 1&2.pdfSatishKhadse3
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Takao Wada
 
Autocad second level tutorial
Autocad second level tutorialAutocad second level tutorial
Autocad second level tutorialJo Padilha
 
Dynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPFDynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPFIJERD Editor
 
AUTOCAD Report
AUTOCAD ReportAUTOCAD Report
AUTOCAD ReportAMIT RAJ
 
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docxasmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docxfredharris32
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics FunctionsSHAKOOR AB
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTvineet raj
 
U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptxmadan r
 
Android based application for graph analysis final report
Android based application for graph analysis final reportAndroid based application for graph analysis final report
Android based application for graph analysis final reportPallab Sarkar
 

Similaire à Java Graphics (20)

Autocad civil project file
Autocad civil project fileAutocad civil project file
Autocad civil project file
 
Graphics software
Graphics softwareGraphics software
Graphics software
 
Q Cad Presentation
Q Cad PresentationQ Cad Presentation
Q Cad Presentation
 
RS and GIS TW- 1&2.pdf
RS and GIS TW- 1&2.pdfRS and GIS TW- 1&2.pdf
RS and GIS TW- 1&2.pdf
 
Auto cad 3d tutorial
Auto cad 3d tutorialAuto cad 3d tutorial
Auto cad 3d tutorial
 
Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Csc406 lecture7 device independence and normalization in Computer graphics(Co...Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Csc406 lecture7 device independence and normalization in Computer graphics(Co...
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 
Autocad second level tutorial
Autocad second level tutorialAutocad second level tutorial
Autocad second level tutorial
 
Dynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPFDynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPF
 
Intake 37 6
Intake 37 6Intake 37 6
Intake 37 6
 
JAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdfJAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdf
 
AUTOCAD Report
AUTOCAD ReportAUTOCAD Report
AUTOCAD Report
 
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docxasmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
 
978 1-58503-717-9-3
978 1-58503-717-9-3978 1-58503-717-9-3
978 1-58503-717-9-3
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORT
 
3 d autocad_2009
3 d autocad_20093 d autocad_2009
3 d autocad_2009
 
U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptx
 
Android based application for graph analysis final report
Android based application for graph analysis final reportAndroid based application for graph analysis final report
Android based application for graph analysis final report
 

Dernier

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 

Dernier (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

Java Graphics

  • 2.  The coordinate system used by a container to position components within it is analogous to the screen coordinate system.  The origin is at the top-left corner of the container, with the positive x-axis running horizontally from left to right, and the positive y-axis running from top to bottom.  The positions of buttons in a JWindow or a JFrame object are specified as a pair of (x, y) pixel coordinates, relative to the origin at the top-left corner of the container object on the screen. The Coordinate System
  • 3.
  • 4. Cont.. The content pane will have its own coordinate system, too, which will be used to position the components that it contains. Every component has its own coordinate system, which will be used to position the component that it contains.
  • 5. Cont.. You also need a coordinate system to draw on a component—to draw a line, for example, you need to be able to specify where it begins and ends in relation to the component
  • 6. Drawing on a Component Device-independent logical coordinate system is called the user coordinate system or user space.  By default, this coordinate system has the same orientation as the system for positioning components in containers. The origin is at the top-left corner; the positive x-axis runs from left to right, and the positive y-axis from top to bottom. Coordinates are usually specified as floating- point values, although you can also use integers.
  • 7. Cont.. A particular graphical output device will have its own device coordinate system This coordinate system has the same orientation as the default user coordinate system, but the coordinate units depend on the characteristics of the device.
  • 8.
  • 9. Cont.. With the default mapping from user coordinates to device coordinates, the units for user coordinates are assumed to be 1/72 of an inch. Since for most screen devices the pixels are approximately 1/72 inch apart, the conversion amounts to an identity transformation.
  • 10. Graphics Contexts The user coordinate system for drawing on a component using Java 2D is encapsulated in an object of type Graphics2D, which is usually referred to as a graphics context. It provides all the tools you need to draw whatever you want on the surface of the component. A graphics context enables you to draw lines, curves, shapes, filled shapes, as well as images, and gives you a great deal of control over the drawing process.
  • 11. Cont.. The information required for converting user coordinates to device coordinates is encapsulated in three different kinds of objects: ❑ A GraphicsEnvironment object encapsulates all the graphics devices (as GraphicsDevice objects) and fonts (as Font objects) that are available on your computer. ❑ A GraphicsDevice object encapsulates information about a particular device, such as a screen or a printer, and stores it in one or more GraphicsConfiguration objects. ❑ A GraphicsConfiguration object defines the characteristics of a particular device, such as a screen or a printer.
  • 12. Cont.. We can draw on a component by implementing the paint() method that is called whenever the component needs to be reconstructed. The another way of drawing on a component is by obtaining a graphics context for a component at any time just by calling its getGraphics() method and then using methods for the Graphics object to specify the drawing operations. If you don’t want to call paint() method directly in some occasion , you have to use repaint() method.
  • 13. An Example, public void paint(Graphics g) { Graphics2D g2D = (Graphics2D)g; // Get a Java 2D device context g2D.setPaint(Color.RED); // Draw in red g2D.draw3DRect(50, 50, 150, 100, true); // Draw a raised 3D rectangle g2D.drawString(“A nice 3D rectangle”, 60, 100); // Draw some text }
  • 14.
  • 15. The Drawing Process  A Graphics2D object maintains a whole heap of information that determines how things are drawn. Most of this information is contained in six attributes within a Graphics2D object: 1. Paint 2. Stroke 3. Font 4. Transform 5. Clip 6. Composite
  • 17. Shapes Classes that define geometric shapes are contained in the java.awt.geom package, but the Shape interface that these classes implement is defined in java.awt. To draw a shape on a component, you just need to pass the object defining the shape to the draw() method for the Graphics2D object for the component.
  • 18. Classes Defining Points Two classes in the java.awt.geom package define points, Point2D.Float and Point2D.Double.
  • 19. Cont.. The operations that each of the three concrete point classes inherits are: Accessing coordinate values Calculating the distance between two points
  • 20. Cont.. OR Comparing points—The equals() method compares the current point with the point object referenced by the argument and returns true if they are equal and false otherwise.
  • 21. Cont.. Setting a new location for a point : setLocation() method is used to set the location of the point.
  • 23.
  • 24. Drawing a Line OR You draw a line using the draw() method for a Graphics2D object
  • 25. Create a Rectangle getx() and gety() are used to retrieve the coordinates of rectangle. Getheight() and getwidth() returns the height and width. You can set the position, width, and height of a rectangle by calling its setRect() method.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33. Filling Objects Once you know how to create and draw a shape, filling it is easy. You just call the fill() method for the Graphics2D object and pass a reference of type Shape to it.  This works for any shape but for sensible results the boundary should be closed.  The way the enclosed region will be filled is determined by the window rule in effect for the shape.
  • 34. Ex., Filling Star public void paint(Graphics g) { Graphics2D g2D = (Graphics2D)g; Star star = new Star(0,0); // Create a star float delta = 60; // Increment between stars float starty = 0; // Starting y position // Draw 3 rows of 4 stars for(int yCount = 0 ; yCount<3; yCount++) { starty += delta; // Increment row position float startx = 0; // Start x position in a row // Draw a row of 4 stars for(int xCount = 0 ; xCount<4; xCount++) { g2D.setPaint(Color.BLUE); // Drawing color blue g2D.draw(star.atLocation(startx += delta, starty)); g2D.setPaint(Color.GREEN); // Color for fill is green g2D.fill(star.getShape()); // Fill the star } } }
  • 35.
  • 38.
  • 39.
  • 41. Using Dialogs A dialog is a window that is displayed within the context of another window—its parent. The JDialog class in the javax.swing package defines dialogs, and a JDialog object is a specialized sort of Window. A JDialog object will typically contain one or more components for displaying information or allowing data to be entered, plus buttons for selection of dialog options (including closing the dialog) together.
  • 42. Modal and Non-Modal Dialogs There are two different kinds of dialog that you can create, and they have distinct operating characteristics. You have a choice of creating either a modal dialog or a non-modal dialog. When you display a modal dialog—typically by selecting a menu item or clicking a button—it inhibits the operation of any other windows in the application until you close the dialog.
  • 43. Cont.. A non-modal dialog can be left on the screen for as long as you want, since it doesn’t block interaction with other windows in the application. You can also switch the focus back and forth between using a non-modal dialog and using any other application windows that are on the screen.
  • 44.
  • 46. Instant Dialogs The JOptionPane class in the javax.swing package defines a number of static methods that will create and display standard modal dialogs for you. The following static methods in the JOptionPane class produce message dialogs: You can refer to various methos of this from our textbook on page no-1009.
  • 47. Input Dialogs JOptionPane also has four static methods that you can use to create standard modal input dialogs: showInputDialog(Object message) eg, String input = JOptionPane.showInputDialog(“Enter Input:”);
  • 48. Cont.. String input = JOptionPane.showInputDialog(null, “Enter Input:”,“Dialog for Input”, JOptionPane.WARNING_MESSAGE);
  • 49. Cont.. String[] choices = {“Money”, “Health”, “Happiness”, “This”, “That”, “The Other”}; String input = (String)JOptionPane.showInputDialog(null, “Choose now...”, “The Choice of a Lifetime”, JOptionPane.QUESTION_MESSAGE, null, // Use default icon choices, // Array of choices choices[1]); // Initial choice
  • 50. Choosing a Custom Color Facility of Choosing Custom Color is provided by the javax.swing.JColorChooser class. Example
  • 51.