A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Programming a Paint Brush in JavaThis program will help you enhance your mouse event concepts in Java. As the title indicates you will be playing with a brush after you go through the tutorial. |
On Friday, February 10th 2006 at 09:34 AM By Dorez Khan (View Profile) ![]() ![]() ![]() ![]() (Rated 3.3 with 15 votes) |
||||||
|
What You need to Know before reading this tutorial: 1. Basic Java 2. Clear concepts of events in java 3. Knowledge of Swing 4. A bit of common sense Explanation The algorithm for a painter program in Java is simple using the event class in awt; You first declare two variables to get the x and y coordinate values; Then using MouseMotionLister you trace the values of x and y coordinates where the mouse is being dragged and then you fill an oval there using fillOval. Program First you need to import the classes required for the program execution, as explained above we are going to use the event class which resides insite awt. Also we are using swing for the Graphical User Interface (GUI) of the program:
Next we Declare a class which extends JFrame,then we declare two variables which are intialized to -10 so that the mouse pointer will start from x and y coordinates of -10 ,then we declare a public function Painter and setup the title of the titlebar using super(),then we add a label telling the user to "Click and drag" on bottom:
Below is the most important structure of the program, we first add MouseMotionLister() then we declare a public function included in MouseMotionListener, named mouseDragged() which detects information related to dragging (dragging as in clicking and moving the mouse simultaneously); Using this function we try to get the values of the x and y coordinates of the application where the mouse is being dragged. We use event.getX() and event.getY() for this purpose. repaint() calls the paint function.
Next we just set the size of window, and set its visibility to true:
Now we have programmed to take the x and y coordinates value, where the drag event is taking place; now the last step is to just paint the area where the event is happening; the below lines just fill an oval on x and y coordinates of application where the mouse cursor is being dragged; you can make the brush thinner by reducing 10 to 5 or a smaller number inside fillOval().
In the lines below we just declare a painter class inside main and set the program up for closing the function. If you do not know about WindowListener you can use below line instead: application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
Project Okay try to alter the above code and modify it. Try to create something such as a brush resizer program, it can be simple... just take input using any means for example two radio buttons having labels "Small" and "Large", and setup different values of brush size, and instead of giving integer values you will declare variables and set values for them according to "Small" and "Large" radio buttons like g.fillOval( xvalue, yvalue, b_thickness1, b_thickness2 ); Hope that the above tutorial has helped you, if you have any questions you can comment below or email me at whosnext886@gmail.com. |
|||||||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||||||
|
|||||||
Current CommentsA Question
How To Draw A Free-Hand Picture With This Tool ?
Please Reply If U Have Any Soluction..
Thank You.
amit.
yeah i would like to see your program please send me a copy of your program on my mail
thank you
I\'d also like a copy if thats possible :D
Thks...
It\'s very nice. please, If you send me a copy of this program. I will be thankful to you.
I would like to have a copy if this project, if possible
This is a very nice tutorial for begnners.
Java swing tutorial and source code contains brief tutorials for various components with examples.
Regards,
Hemanth
http://www.java-swing-tutorial.com
yeah i would like to see your program please send me a copy of your program on my mail
thank you
would you please send me a copy of your program on my email with code
thank you
send me a copy of your java programs....
yup good simple one.can i keep in touch with to share more resources.and i think i can also learn more from u. can u mail me.
I would like a copy of this project, if is possible, please.
Thank you
question:-
In paintbrush proj. I am using canvas but problem is
when we select the menubar then menuItems are go backside
of the canvas.
please help me...
i need java source code that can do the task of "paint" .i need it to have an option button with an option oval,rectangle,line and with a color option red,green,blue.
many thanks for any support that you may extend to me
Question:
How i write text on selected area with this code.If possible please sent copy of code in my mail and solve my problem soon.
Please reply soon
Thank You
i would love to have a copy of this project.
thank you.if possible please send me thru the above mail id.
i would like to see your program please send me a copy of your program on my mail
thank you
I would like to see your source code, if is it possible, please send on my e-mail, thanks.
I need java source code that can do the task of "paint" .i need it to have an option button with an option oval,rectangle,line and with a palet color.
I need it to have an option form 3D.
Many thanks for any support that you may extend to me.
I am Colombian nothing inglish.
Just like most of the previous requesting people I need the source code as well, I need it to be able to have the shapes(rectangle, oval etc.) resized and rotated. I have my source code which is good for drawing only but I'm having a very hard time with using matrix rotating and resizing so PLEASE, give me a hand. It's very urgent because it is for a very important school assignment and if I don't do it I will fail. Thank you in advance.
Can you give me a paint brush coding??
Can you give me a paint brush coding??
Can you give me a paint brush coding??
Hi,
I am doing an assignment regarding a drawing tool. I would like to see your source code, if it is possible, please send on my e-mail. it is "sandun_2222@yahoo.com"
Thanks alot,
Sandun
Hi,
I like this idea.
I m student of M.Sc. nd i have to do project this year.
So, can you suggest some project topics like this or any other which can help me.
Plz reply.
Hi,
I like this idea.
I m student of M.Sc. nd i have to do project this year.
So, can you suggest some project topics like this or any other which can help me.
Plz reply.
source code site
I will try with your suport,
I would like to have a copy if this project, if possible
thank you sir
Hi,
I like this idea.
I m student of M.Sc. nd i have to do project this year.
So, can you suggest some project topics like this or any other which can help me.
Plz reply. Can you give me a paint brush coding??
I want java source code to implement paint brush in java painter
Some parts were hard to get. When it said addMouseMotionListener, it turned out to be an error.
i want java coding of paint brush as i am working on dis project...can u jst give me d coding as well as explanztion so that i would get sum help
thanking u!!
Hi
Youre progarm sorce code is best.But less, please send to me a full source code of paint in java to my email.
Hi
Youre progarm sorce code is best.But less, please send to me a full source code of paint in java to my email.
nice share :)
its a nice.
i would be pleased if u send mme a copy of this plz wid coding................
thanks
thank u very much for this code.
Sir,
I want to learn hw the paint brush was developed, if u send the source code that will very helpful for me.
Thanks alot..
Sir,
I want to learn hw the paint brush was developed, if u send the source code that will very helpful for me.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
/*<applet code="Painter" width=350 height=250>
</applet>*/
public class Painter extends Applet
{
int xvalue,yvalue,x1,y1;
public void init()
{
addMouseListener(new MouseHandler());
addMouseMotionListener(new MouseMotionHandler());
}
class MouseHandler implements MouseListener
{
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
xvalue=0;yvalue=0;
x1=0;y1=0;
}
public void mouseClicked(MouseEvent e)
{
xvalue=e.getX();
yvalue=e.getY();
//repaint();
}
public void mouseEntered(MouseEvent e)
{}
public void mouseExited(MouseEvent e)
{}
}
class MouseMotionHandler implements MouseMotionListener
{
public void mouseDragged(MouseEvent e)
{
x1=e.getX();
y1=e.getY();
repaint();
}
public void mouseMoved(MouseEvent e)
{
//x1=e.getX();
//y1=e.getY();
//repaint();
}
}
public void paint(Graphics g)
{
g.drawOval(xvalue,yvalue,x1,y1);
}
}
hello ,how to draw a free hand picture with mouse can u send the code to my mail
سلام عليكم
لو سمحتو بدي برنامج الرسام بلغة الجافا
can u tell me the advantages of paint application using java applet over others??
Programming a Paint in Java
Programming a Paint in Java
Programming a Paint in Java
Programming a Paint in Java
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
Hello Sir,
I am a Student of MSc IT..
Can u please give some projects topics like this for my project..
thank u.
waiting 4 reply..
hi sir,
i would like to have some help in my java paint program if you please
the problem is that i could not know how to resize the shapes drawn
thanks
hi sir,
i would like to have some help in my java paint program if you please
the problem is that i could not know how to resize the shapes drawn
thanks
its very useful for freshers, and the persons who have passion to learn java.
its good topic for a project so can u please send me the coding of this "paint brush" with the explanation so that it will be helpful for me
plz
Thank u
Hi ...
This is very interesting to me so pls send full source code of paint in java to my email.
send me a complete java code for paintig
hi everyone if you need any kind of projects in java
you can mail me on-quimztech@gmail.com
hi everyone if you need any kind of projects in java
you can mail me on-quimztech@gmail.com
Hello,
could u please send the whole code to my mail is.. thanks a lot.
Related Tutorials
Related Source Code
Java Job Search