After seen Johns how to use the java paint function. I thought I could share my tutorial how to make one.
So lets begin...
So lets fix the false statment(We had to do this due to you starting it with a click it will automatically enter a dot on the screen...Code:import java.awt.*; public class prickar extends java.applet.Applet { private int mouseX, mouseY; private boolean mouseclicked = false;//statment of starting the app public void init() { setBackground (Color.white);//Our background for the screen }
Lets continue...Code:public boolean mouseDown (Event e, int x, int y ) {//applying the mouse when in use mouseX=x; mouseY=y;//coordinations mouseclicked = true;//Here is our old false statment fixed when we really want to paint. repaint();//Allowing use to paint how many times we want return true;//return it to the screen "true" }
Last part...Code:public void paint ( Graphics g ) {//To enable painting g.setColor (Color.black);//paint color if (mouseclicked) {//if you click with whatever mouse button g.fillOval (mouseX, mouseY, 12, 12);//The screen will be painted with a ovaldot 12x12 in size mouseclicked = false;//This means you havn't clicked it will be false and screen won't be "colored" } }
Whole codeCode:public void update ( Graphics g ) {//Updating your screen so it will be active and the painted things won't disappear paint (g); } }
So thats my tutorial, thanks John for learing meCode:import java.awt.*; public class dots extends java.applet.Applet { private int mouseX, mouseY; private boolean mouseclicked = false; public void init() { setBackground (Color.white); } public boolean mouseDown (Event e, int x, int y ) { mouseX=x; mouseY=y; mouseclicked = true; repaint(); return true; } public void paint ( Graphics g ) { g.setColor (Color.black); if (mouseclicked) { g.fillOval (mouseX, mouseY, 12, 12); mouseclicked = false; } } public void update ( Graphics g ) { paint (g); } }![]()
Nice! I'm glad I could inspire you to write your own![]()
Thanks![]()
Wow nice and easy tutorial. thanks for the contribution+REP
the code is with you
Thanks
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks