Forum Topic: Java: Simple Paint Program

(1,195 views • 12 replies)

This topic is 1 page long.

<< < > >>
None

Jordan

Reply To Post Reply & Quote

Posted at: 6/8/06 07:27 AM

Jordan DARK LEVEL 14

Sign-Up: 04/23/06

Posts: 2,833

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.


None

Jordan

Reply To Post Reply & Quote

Posted at: 6/8/06 08:35 AM

Jordan DARK LEVEL 14

Sign-Up: 04/23/06

Posts: 2,833


None

seel

Reply To Post Reply & Quote

Posted at: 6/8/06 10:41 AM

seel FAB LEVEL 19

Sign-Up: 06/27/05

Posts: 2,193

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


None

Jordan

Reply To Post Reply & Quote

Posted at: 6/8/06 12:07 PM

Jordan DARK LEVEL 14

Sign-Up: 04/23/06

Posts: 2,833

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!


None

Craige

Reply To Post Reply & Quote

Posted at: 6/8/06 07:02 PM

Craige LIGHT LEVEL 08

Sign-Up: 07/17/04

Posts: 3,072

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


None

Jordan

Reply To Post Reply & Quote

Posted at: 7/18/06 04:05 PM

Jordan DARK LEVEL 14

Sign-Up: 04/23/06

Posts: 2,833

w00t and example can be found...

HERE!


None

Momo-the-Monkey

Reply To Post Reply & Quote

Posted at: 7/18/06 08:59 PM

Momo-the-Monkey EVIL LEVEL 34

Sign-Up: 10/15/05

Posts: 3,249

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...!

Randosity is something you should see...
You should also see Gir's Soundboard...
[ PHP: Main | Music ]

BBS Signature

Questioning

Animaniak

Reply To Post Reply & Quote

Posted at: 11/26/06 08:43 PM

Animaniak LIGHT LEVEL 09

Sign-Up: 09/22/06

Posts: 329

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


None

elbekko

Reply To Post Reply & Quote

Posted at: 11/27/06 11:59 AM

elbekko EVIL LEVEL 16

Sign-Up: 07/23/04

Posts: 6,587

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

None

Jordan

Reply To Post Reply & Quote

Posted at: 11/27/06 12:05 PM

Jordan DARK LEVEL 14

Sign-Up: 04/23/06

Posts: 2,833

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/


None

UnknownFear

Reply To Post Reply & Quote

Posted at: 2/3/07 11:07 AM

UnknownFear FAB LEVEL 34

Sign-Up: 02/27/04

Posts: 6,912

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

Blog
[ T | F | G/MSN ]
--Ubuntu 9.10 "Karmic Koala" User--


None

Mister-Mind

Reply To Post Reply & Quote

Posted at: 2/3/07 11:14 AM

Mister-Mind EVIL LEVEL 07

Sign-Up: 07/01/06

Posts: 2,196

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.


None

amaterasu

Reply To Post Reply & Quote

Posted at: 2/3/07 11:16 AM

amaterasu LIGHT LEVEL 07

Sign-Up: 03/07/04

Posts: 2,050

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.

NexusTK Characters: Stegmann Cirucci Ulquiorra Ganju

Do you like chill music? Check out my latest work!

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 07:49 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!