Results 1 to 18 of 18

Thread: Applets: Paint & Graphics

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Ithaca, NY
    Posts
    145

    Applets: Paint & Graphics

    Can anyone link me to a GOOD tutorial for applets and the paint method and how graphics work all around? I've searched and searched but can't find a site that's really explained how to use graphics to paint on the screen from the view of a person who's never used that function of Java before. I just need to get the basic idea of it down and I haven't been able to do that with the walk-throughs that I've found.

  2. #2
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Applets: Paint & Graphics

    Check the Sun documentation,

    Paint class.

    Graphic class.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Ithaca, NY
    Posts
    145

    Re: Applets: Paint & Graphics

    I'm looking for more of a tutorial, not a manual.

  4. #4
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Applets: Paint & Graphics

    Documentation also come with examples. But not bulky ones.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Ithaca, NY
    Posts
    145

    Re: Applets: Paint & Graphics

    If the Java documentation were as good as PHP's I'd be set but that's not really the case.

    Anyway, I could still use a good example....

  6. #6
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Applets: Paint & Graphics

    It's up to you. I believe that Java documentation is the best one in Java world.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  7. #7
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Applets: Paint & Graphics

    Quote Originally Posted by eranga262154
    It's up to you. I believe that Java documentation is the best one in Java world.
    Unless you are a copy, paste type of developer
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Ithaca, NY
    Posts
    145

    Re: Applets: Paint & Graphics

    I've never copied code in my life... I just don't understand Java graphics and I can't find any examples that explain it from the stance of someone who has never used them.

    I understand basic draw functions and whatnot I just don't understand things like the repaint() method and how to get it to paint what I want, when I want it to.

  9. #9
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Applets: Paint & Graphics

    If that's the case, you might find this tutorial interesting.
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  10. #10
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Applets: Paint & Graphics

    Quote Originally Posted by ComputerJy
    Unless you are a copy, paste type of developer
    I Never do that. I used codes on my own practice.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  11. #11
    Member
    Join Date
    Jun 2007
    Location
    England
    Posts
    61

    Re: Applets: Paint & Graphics

    Check this site out.

    It has good tutorials on writing Java applets for Game Development.

    Covers everything you need nicely...

    http://www.javacooperation.gmxhome.d...lStartEng.html

  12. #12
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Applets: Paint & Graphics

    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  13. #13
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    Re: Applets: Paint & Graphics

    Sorry to ask another question on this thread, but it's sort of related. Is there any way to get Java to draw gradients and/or with semi-transparent colors. This is easy to do in .NET, but I haven't found the APIs to do it in Java.
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  14. #14
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Applets: Paint & Graphics

    I don't know exact API for this. But for the gradients you can use, constructor Gradient() create gradient color with getGradient() method, and GradientPaint() use to fill the gradient color.

    As far as I've remember, GradientPaint() syntax use as follows.

    Code:
    GradientPaint(start_x, start_y, start_color, end_x, end_x, end_color, true)
    true define the repeatability of starting and ending colors.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  15. #15
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Applets: Paint & Graphics

    Here is a working code sample (it's easier than you might think)
    Code:
    import java.awt.Color;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import javax.swing.*;
    
    public class Test extends JFrame {
    
        public Test() {
            super("Test");
            this.setSize(300, 300);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setVisible(true);
        }
    
        @Override
        public void paint(Graphics g) {
            super.paint(g);
            GradientPaint paint = new GradientPaint(0, 0, Color.BLUE, 300, 300, Color.BLACK);
            ((Graphics2D) g).setPaint(paint);
            g.fillRect(0, 0, 300, 300);
        }
    
        public static void main(String[] args) {
            new Test();
        }
    }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  16. #16
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Applets: Paint & Graphics

    Quote Originally Posted by ComputerJy
    Here is a working code sample (it's easier than you might think)

    Is it for me.

    On you code, my tip is correct. One question there. You don't use that boolean option in GradientPaint(), means that the default is true, or I'm wrong with parameters list?

    On this machine I've work now haven't setup Java yet and I can't test your code.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  17. #17
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Applets: Paint & Graphics

    Quote Originally Posted by eranga262154

    Is it for me.

    On you code, my tip is correct. One question there. You don't use that boolean option in GradientPaint(), means that the default is true, or I'm wrong with parameters list?

    On this machine I've work now haven't setup Java yet and I can't test your code.
    Just like any other boolean, if it's not set the default value is false.

    And by the way, I've never said your code is wrong
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  18. #18
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Applets: Paint & Graphics

    Quote Originally Posted by ComputerJy
    And by the way, I've never said your code is wrong

    No way pal just checking that I've missing something
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

Posting Permissions

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



Click Here to Expand Forum to Full Width