00:00
00:00

Our goal is for Newgrounds to be ad free for everyone! Become a Supporter today and help make this dream a reality!

Java: Simple Paint Program

12,033 Views | 13 Replies
New Topic Respond to this Topic

Java: Simple Paint Program 2006-06-08 07:27:13


Hello this is my first tutorial so bare with me.
In this tutorial i will show you how to make the .java file for a simple paint program and show you how to change the background/paint colours.
(this tutorial will not explain how to compile)

Ok so start up your text editor(e.g. notepad).
then copy and paste in the below code:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Paint extends Applet
implements MouseMotionListener {

int width, height;
Image backbuffer;
Graphics backg;

public void init() {
width = getSize().width;
height = getSize().height;

backbuffer = createImage( width, height );
backg = backbuffer.getGraphics();
backg.setColor( Color.black );
backg.fillRect( 0, 0, width, height );
backg.setColor( Color.blue );

addMouseMotionListener( this );
}
public void mouseMoved( MouseEvent e ) { }
public void mouseDragged( MouseEvent e ) {
int x = e.getX();
int y = e.getY();
backg.fillOval(x-10,y-10,20,20);
repaint();
e.consume();
}

public void update( Graphics g ) {
g.drawImage( backbuffer, 0, 0, this );
}
public void paint( Graphics g ) {
update( g );
}
}

and save this file as: (DO NOT SAVE AS ANYTHING ELSE)(CASE SENSITIVE)
Paint.java

now compile this code into a .class file and add it to a webpage to veiw.

now i will tell you how to change the colours.

BACKGROUND:
where it says this: backg.setColor( Color.black );
change where it says black to your desired background colour.

PAINT:
where it says this: backg.setColor( Color.blue );
change where it says blue to your desired paint colour.

And your simple paint program is done!

Please report any errors.

Jordan, Doodle-Flash.

Response to Java: Simple Paint Program 2006-06-08 08:35:29


Response to Java: Simple Paint Program 2006-06-08 10:41:57


Well you should have explained most of it so that ppl would understand whats going on.. keep that in mind to the next tutorial..

Response to Java: Simple Paint Program 2006-06-08 12:07:44


Changing paint size:

where it says:
backg.fillOval(x-10,y-10,20,20);

you can change the numbers to make the paint brush size bigger or smaller.
i would highly recomend:
first two the same
last two the same
last two double the first two
as this will make sure the brush is always circle and the cursor is at the center of the brush.

so for example you could change it to:
backg.fillOval(x-20,y-20,40,40);
for a double size brush!

note: the first two determine where the cursor is in comparison to the brush and the last two determine the size of the brush!

Response to Java: Simple Paint Program 2006-06-08 19:02:14


Yeah, this was not much of a tutorial. It did not tutor or anything. You need to explain how things work.

Response to Java: Simple Paint Program 2006-07-18 16:05:14


w00t and example can be found...

HERE!

Response to Java: Simple Paint Program 2006-07-18 20:59:30


cool. I likey. A little simple, but that's alright.

hey, want to make me anymore? I'm getting kind of low. :p

And, do try to explain it more next time ^_^ just for kicks...!


Hello, from the past!

[ PHP: Main ]

BBS Signature

Response to Java: Simple Paint Program 2006-11-26 20:43:01


i dont get wat you mean by compile it into a .class file.......

Response to Java: Simple Paint Program 2006-11-27 11:59:48


At 7/18/06 04:05 PM, Jordan wrote: w00t and example can be found...

HERE!

"The first, of what could be many java applets on our site! :D"
Oh dear lord, please don't :P


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature

Response to Java: Simple Paint Program 2006-11-27 12:05:56


At 11/27/06 11:59 AM, elbekko wrote: "The first, of what could be many java applets on our site! :D"
Oh dear lord, please don't :P

Lol, that is the very first DoodleFlash:
http://www.doodle-flash.co.uk/lang/en/DoodleF lash/pages/

Response to Java: Simple Paint Program 2007-02-03 11:07:41


Which program can I use to complie Java code? Just a simple, Java compiler.

Response to Java: Simple Paint Program 2007-02-03 11:14:11


At 2/3/07 11:07 AM, UnknownFear wrote: Which program can I use to complie Java code? Just a simple, Java compiler.

Yeah, theres one on his site, he made one. Im not sure if its there but just ask jordan.

Response to Java: Simple Paint Program 2007-02-03 11:16:25


At 2/3/07 11:07 AM, UnknownFear wrote: Which program can I use to complie Java code? Just a simple, Java compiler.

you have to go to java.sun.com and get the sdk.

or, if you're more adventurous, you can always use the gnu java compiler.


beep

BBS Signature

Response to Java: Simple Paint Program 2010-06-26 21:41:25


For fucks sake, at least explain what this shit does.