A Minor Project
A Minor Project
ON
A SIMPLE PROJECT TO DRAW PAINT (JAVA
LANGUAGE)
Submitted in partial fulfillment of
requirement of Bachelor of Computer
Application
Session…. 2019-2020
BCA 5th semester
Submitted to-
MR.RAJNEESH KUMAR
SUBMITTED BY-
MONU RAJPUT
ROLL NO.
1705255011033
Contents
Content
ABSTRACT ....................................................................................................................................
1
1. Introduction ............................................................................................................................. 3
4.3 Components.................................................................................................................... 18
5. Conclusion.............................................................................................................................. 25
References ..................................................................................................................................... 26
ABSTRACT
Writing graphics applications in Java using Swing can be quite a
daunting experience which requires understanding of some large
libraries, and fairly advanced aspects of Java. In a graphical system,
a windowing toolkit is usually responsible for providing a
framework to make it relatively painless for a graphical user
interface (GUI) to render the right bits to the screen at the right
time. Both the AWT (abstract windowing toolkit) and Swing
provide such a framework. In this report, we designed and
developed a simple painter project used to enable a user to draw any
shape and any integrated graphic with any color using FreeHand
(move the mouse using your hand to draw any shape and specify
the coordinate in JPanel). Several tools such as Undo and Redo
process, Clear JPanel, Set Background Color & set Foreground
Color, Save paint (Panel) to file ( *. JPG; *. GIF; *.* ), and Open
paint from image file are considered. The purpose of this project is
to give you practice with graphical user interface programming in
Java. This project implemented using the components from Java's
awt and swing library in the Java programming language (NetBenas
IDE7.2.1). As the final result of our project is enabling you to use
FreeHand to draw as an easy way to draw the Circle, Line,
Rectangle, Square, and Oval, and integrated graphics such as a car,
a street, a football stadium, traffic signals and others. Keywords:
NetBeans IDE 7.2.1, AWT, Swing, GUI
Object
Containert
Panel
Applet
2.4 Shapes
The Graphics class includes a large number of instance methods
for drawing various shapes, such as lines, rectangles, and ovals.
The shapes are specified using the (x,y) coordinate system described
above. They are drawn in the current drawing color of the
graphics context. The current drawing color is set to the foreground
color of the component when the graphics context is created, but it
can be changed at any time using the setColor() method. Here is a
list of some of
10 the most important drawing methods. With all these commands,
any drawing that is done outside the boundaries of the component is
ignored. Note that all these methods are in the Graphics class, so
they all must be called through an object of type Graphics.
drawString(String str, int x, int y):
Draws the text given by the string str. The string is drawn using the
current color and font of the graphics context. x specifies the
position of the left end of the string. y is the y-coordinate of the
baseline of the string. The baseline is a horizontal line on which the
characters rest. Some parts of the characters, such as the tail on a y
or g, extend below the baseline.
drawLine(int x1, int y1, int x2, int y2):
Draws a line from the point (x1,y1) to the point (x2,y2).
drawRect(int x, int y, int width, int height):
Draws the outline of a rectangle. The upper left corner is at (x,y),
and the width and height of the rectangle are as specified. If width
equals height, then the rectangle is a square. If the width or the
height is negative, then nothing is drawn.
drawOval(int x, int y, int width, int height):
Draws the outline of an oval. The oval is one that just fits inside the
rectangle specified by x, y, width, and height. If width equals height,
the oval is a circle.
drawRoundRect(int x, int y, int width, int height, int xdiam, int
ydiam):
Draws the outline of a rectangle with rounded corners. The basic
rectangle is specified by x, y, width, and height, but the corners are
rounded. The degree of rounding is given by xdiam and ydiam. The
corners are arcs of an ellipse with horizontal diameter xdiam and
vertical diameter ydiam. A typical value for xdiam and ydiam is 16,
but the value used should really depend on how big the rectangle is.
draw3DRect(int x, int y, int width, int height, boolean raised):
Draws the outline of a rectangle that is supposed to have a three-
dimensional effect, as if it is raised from the screen or pushed into
the screen. The basic rectangle is specified by x, y, width, and
height.
drawArc(int x, int y, int width, int height, int startAngle, int
arcAngle):
Draws part of the oval that just fits inside the rectangle specified by
x, y, width, and height. fillRect(int x, int y, int width, int height):
Draws a filled-in rectangle. This fills in the interior of the rectangle
that would be drawn by drawRect(x,y,width,height).
2.5 Graphics2D
This Graphics2D class extends the Graphics class to provide more
sophisticated control over
geometry, coordinate transformations, color management, and
text layout. This is the
fundamental class for rendering 2-dimensional shapes, text and
images on the Java(tm) platform.
All drawing in Java is done through an object of type Graphics.
The Graphics class provides
basic commands for such things as drawing shapes and text and for
selecting a drawing color.
These commands are adequate in many cases, but they fall far short
of what’s needed in a serious
computer graphics program. Java has another class, Graphics2D,
that provides a larger set of
drawing operations. Graphics2D is a sub-class of Graphics, so all
the methods from the Graphics
class are also available in a Graphics2D. The paintComponent()
method of a JComponent gives
you a graphics context of type Graphics that you can use for
drawing on the component. In fact,
the graphics context actually belongs to the sub-class Graphics2D
(in Java version 1.2 and later),
and can be type-cast to gain access to the advanced Graphics2D
drawing methods:
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2;
g2 = (Graphics2D)g;
.
. // Draw on the component using g2.
.
}
IN OUR EXAMPLE
public void draw(Graphics2D ga){
ga.setColor(color);
if (!IsFillColor)
ga.drawArc(getX1(), getY1(), getwidth(), getheight(), 0,
360);
else
ga.fillArc(getX1(), getY1(), getwidth(), getheight(), 0, 360);
}
5. Conclusion
This report presents an introduction to Java and how Java is used to
build graphics and what are
the tools that can be used to develop graphics and drawing required
shapes.
This was an introduction to the main goal of our report that
presented that is design and
development a simple Painter project used to draw any shape
(Circle, Line, Rectangle, Square,
and Oval using FreeHand, Undo and Redo process, Clear JPanel,
Set Background Color & set
Foreground Color, Save paint (Panel) to file ( *. JPG; *. GIF; *.* ),
and Open paint from image
file are considered. The system enables you to use Free Hand to
draw (move the mouse using
your hand to draw any shape and specify the coordinate in JPanel)
as an easy way to draw the
integrated paint, for example, a car , a street , a football stadium ,
traffic signals and others.
References
[1] "Programming Language Popularity". 2009. Retrieved 2009-01-
16.
[2] "TIOBE Programming Community Index". 2009. Retrieved
2009-05-06
[3] http://www.csci.csusb.edu/dick/samples/java.html, 2011, Thu
Aug 25 21:04:36 PDT 2011
[4] Monica Pawlan , Essentials of the Java Programming Language
A Hands-On Guide
[5] David J. Eck , Introduction to Programming Using Java ,
Version 6.0, June 2011 (Version
6.0.2, with minor corrections, May 2013)
[6] Mads Rosendahl, Introduction to graphics programming in
Java, February 13, 2009
[7] 2D Graphics (The Java™ Tutorials) - Oracle Documentation,
http://docs.oracle.com/javase/tutorial/2d/overview/index.html,
Copyright © 1995, 2013 Oracle
[8] http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html
, 2013
[9]
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics2D.html,
2013
[10] Oracle Technology,
http://www.oracle.com/technetwork/java/painting-
140037.html#callback.