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.