+ Reply to Thread
Results 1 to 7 of 7

Thread: Tutorial paint dots(simple version)

  1. #1
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Tutorial paint dots(simple version)

    After seen Johns how to use the java paint function. I thought I could share my tutorial how to make one.

    So lets begin...
    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
     	  }
    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:
    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"
        }
    Lets continue...
    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"
            }
        }
    Last part...
    Code:
    public void  update  ( Graphics g )  {//Updating your screen so it will be active and the painted things won't disappear
    		paint (g);
    	}
    }
    Whole code
    Code:
    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);
    	}
    }
    So thats my tutorial, thanks John for learing me

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: Tutorial paint dots(simple version)

    Nice! I'm glad I could inspire you to write your own

  4. #3
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Tutorial paint dots(simple version)

    Quote Originally Posted by John View Post
    Nice! I'm glad I could inspire you to write your own
    Thanks

  5. #4
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: Tutorial paint dots(simple version)

    Great tutorial! +rep given.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  6. #5
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Tutorial paint dots(simple version)

    Thanks

  7. #6
    Deathcry's Avatar
    Deathcry is offline Learning Programmer
    Join Date
    Feb 2007
    Posts
    69
    Rep Power
    0

    Re: Tutorial paint dots(simple version)

    Wow nice and easy tutorial. thanks for the contribution +REP
    the code is with you

  8. #7
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Tutorial paint dots(simple version)

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 02-10-2011, 11:02 AM
  2. JComboBox - Simple Version !
    By Turk4n in forum Java Tutorials
    Replies: 9
    Last Post: 08-07-2009, 10:22 PM
  3. CodeCall's First Applet - Simple Version !
    By Turk4n in forum Java Tutorials
    Replies: 13
    Last Post: 01-15-2009, 01:09 AM
  4. ArrayList - Simple version !
    By Turk4n in forum Java Tutorials
    Replies: 14
    Last Post: 01-09-2009, 04:57 AM
  5. Abstract method(SIMPLE VERSION)
    By Turk4n in forum Java Tutorials
    Replies: 2
    Last Post: 09-20-2008, 12:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts