Draw A Paint Using Java

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Draw a paint using java

PROJECT REPORT

Submitted in Partial Fulfillment of the requirements for the Award of the Degree of

BACHELOR OF BUSINESS ADMINISTRATION

IN

COMPUTER APPLICATION

By

GAURAV SONAWANE (Roll no:-58)

SHUBHAM JAGDALE (Roll no:-57)

STUDENTS OF THIRD YEAR BBA_CA

Under the Esteemed Guidance of

PROF.P.GUDAGHE

OF

DEPARTMENT OF BBA(COMPUTER APPLICATION)

K. J. Somaiya College of Arts, Commerce and Science,


Kopargaon- 423601
FOR ACADEMIC YEAR 2022-2023
1. ACKNOWLEDGEMENT

It is indeed with a great pleasure and immense


sense of gratitude that we acknowledge the help of these
individuals. We are highly indebted to our Principal Dr. B.
S.YADAV, k.j.somaiya college, kopargoan for the
facilities provided to accomplish the draw a paint
using java project.
We would like to thank our Prof. P.G.
Gudaghe, Head of the Department of
BBA(COMPUTER APPLICATION),K.J.SOMAIYA
COLLEGE,KOPARGOAN,for this constructive criticism
throughout our project.
We feel elated in manifesting our sense of
gratitude to our internal project guide Prof. P.G.
GUDAGHE, Associate Professor, Department of
BBA(COMPUTER APPLICATION),K.J.SOMAIYA
COLLEGE,KOPARGOAN. He has been a constant
source of inspiration for us and we are very deeply
thankful to him for his support and valuable advice.
We extremely grateful to our Departmental
staff members and Non-teaching staff members for their
extreme help throughout the project.

Project Associates: (Student Name)


(MR Gaurav sonawane)
(Mr Shubham jagdale )
STUDENTS OF THIRD YEAR BBA_CA
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.
ABSTRACT

1. Introduction
1.1 Overview
1.2 Object-oriented Programming

1.3 The Basic GUI (graphical user interface ) Application 2. Graphics and
Painting
2.1 Overview of the Java 2D API Concepts
2.2 Coordinates
2.3 Colors
2.4 Shapes

2.5 Graphics2D 3. Painting in AWT and Swing


3.1 Evolution of the Swing Paint System

3.2 Painting in AWT 4. Design and Development our project


4.1 Program Ability (Objectives):
4.2 System Framework
4.3 Components
4.4 Program Structure and Results
4.4.1Preview (System Interface)
4.4.2Undo and Redo
4.4.3SetColor
4.4.4setBackColor
4.4.5Save to File
4.4.6Open Image from File
5. Conclusion
6. References
2. Introduction
1.1 Overview
Java is a general-purpose, concurrent, class-based, object-oriented computer
programming language that is specifically designed to have as few implementation
dependencies as possible. It is intended to let application developers "write once, run
anywhere" (WORA), meaning that code that runs on one platform does not need to
be recompiled to run on another. Java applications are typically compiled to byte
code (class file) that can run on any Java virtual machine (JVM) regardless of
computer architecture. Java is, as of 2012, one of the most popular programming
languages in use, particularly for client-server web applications, with a reported 10
million users [1][2]. Java was originally developed by James Gosling at Sun
Microsystems (which has since merged into Oracle Corporation) and released in
1995 as a core component of Sun Microsystems' Java platform.
Java [3] can be used to write applications and applets. A Java application is similar to
any other high-level language program: It can only be compiled and then run on the
same machine. An applet is compiled on one machine, stored on a server in binary,
and can be sent to another machine over the Internet to be interpreted by a Java-
aware browser. Java comes with a large library of ready-made classes and objects.
The key difference between Java 1.0 and 1.1 was in this library. Similarly, Java 2.0
has a very much larger library for handling user interfaces (Swing by name) but only
small changes to the core of the language.

1.2 Object-oriented Programming


Java supports object-oriented programming techniques that are based on a hierarchy of
classes and well-defined and cooperating objects [4].
Classes: A class is a structure that defines the data and the methods to work on that
data. When you write programs in Java, all program data is wrapped in a class,
whether it is a class you write or a class you use from the Java API libraries. Classes
in the Java API libraries define a set of objects that share a common structure and
behavior.
Objects: An instance is a synonym for object. A newly created instance has data
members and methods as defined by the class for that instance.
Well-Defined Boundaries and Cooperation: Class definitions must allow objects to
cooperate during execution.
Inheritance and Polymorphism: One object-oriented concept that helps objects work
together is inheritance. Inheritance defines relationships among classes in an object-
oriented language. The relationship is one of parent to child where the child or
extending class inherits all the attributes (methods and data) of the parent class. In
Java, all classes descend from java.lang.Object and inherit its methods. Figure 1
shows the class hierarchy as it descends from java.lang.Objectfor the classes in the
user interface example above. The java.lang.Objectmethods are also shown because
they are inherited and implemented by all of its subclasses, which is every class in
the Java API libraries. java.lang.Objectdefines the core set of behaviors that all
classes have in common.

1.  The java.awt.Graphics Class: Graphics Context and


Custom Painting
A graphics context provides the capabilities of drawing on the screen. The graphics context
maintains states such as the color and font used in drawing, as well as interacting with the
underlying operating system to perform the drawing. In Java, custom painting is done via
the java.awt.Graphics class, which manages a graphics context, and provides a set of device-
independent methods for drawing texts, figures and images on the screen on different platforms.
The java.awt.Graphics is an abstract class, as the actual act of drawing is system-dependent and
device-dependent. Each operating platform will provide a subclass of Graphics to perform the
actual drawing under the platform, but conform to the specification defined in Graphics.
Object

Containert

Panel

Applet

SimpleApplet

Figure 1. Object Hierarchy


Figure 2. System framework for our Painter Project

 Operation Model: Events are executed requested by the user and show the result
of the required on panel or frame.
1. The events on the buttons or panel such as mouseClicked, MousePressed,
MouseReleased, MouseMoved, MouseDragged, and FocusGained, when
the user released events the program call the subroutine to achieve
operation required.
2. After completing execute the subroutine show the result on panel.

4.3 Components
Our project contents from several classes as follows:
- Main_DrawPaintProject.java (Main Program)
- InterfaceForm.java (Main program interface)
- Shape.java
- Command.java
- Point.java
- DrawLine.java
- DrawCircle.java
- DrawRectangle.java
- DrawSquare.java
- DrawOval.java - DrawString

More detail about the collection components shown in Figure 3.

Figure 3. Collection Framework


4.4 Program Structure and Results
This is the public methods of each class which collaboratively used between classes

4.4.1 Preview (System Interface)


Figure 4 shows the main interface of our project and what abilities available
(tools) are in our program for drawing, coloring, and save and open image file. Also
explain how you can draw an integrated paint from several geometric shapes and
different colors, for example, a car, a street, a football stadium, traffic signals and
others.

package com.onlinetutorialspoint.swing;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;

import javax.swing.JPanel;

public class JColorChooserDemo extends JFrame {


private JButton button;
private Color color;
private JPanel colorPanel;

public JColorChooserDemo(){
super("JColorChooser Example");

colorPanel = new JPanel();

button = new JButton("Apply Color");

button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e)
{ color =
JColorChooser.showDialog(JColorChooserDe
mo.this, "Pick Color", color); if(color == null)
color = Color.WHITE;
colorPanel.setBackground(color);
}
});
add(colorPanel,BorderLayout.CENTER);
add(button,BorderLayout.SOUTH);
setSize(400, 130);
setVisible(true);
}
public static void main(String[] args) {
JColorChooserDemo colorChooser = new
JColorChooserDemo();
colorChooser.setDefaultCloseOperation(JFrame.EXIT_ON_CL
OSE);
}

Output:

Preview (System Interface


3. 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.htm l,
Copyright © 1995, 2013 Oracle

[8] http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.h
tml , 2013

[9] http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics2 D.html,


2013

[10] OracleTechnology,
http://www.oracle.com/technetwork/java/painting-
140037.html#callback

You might also like