Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2011
    Location
    Belgium
    Posts
    25
    Rep Power
    0

    Default help with Graphics method

    Hey, I'm looking for help with a Graphics methode.

    I want a method to paint an image based on a number (int) value.

    Something like this:

    public void PaintImage(int value, Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.drawImage(Images[value],780,10,null);
    }

    Images is a bufferedImage[].

    the problem starts when I try to access this method from an other class.

    Something like this doesn't work:

    int pictogramValue = 1;
    plaatserPictogram.PaintImage(pictogramValue,Graphi cs g);

    why not? And what's the solution for this, so I can paint the right image on my canvas?
    Last edited by The original stinger; 05-21-2012 at 08:13 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: help with Graphics method

    I don't really know what you're asking. If you want help, you should provide an SSCCE that demonstrates the problem.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: help with Graphics method

    doesn't work
    Can you explain what happens? Post the full text of any error messages.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: help with Graphics method

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: help with Graphics method

    Java Code:
    plaatserPictogram.PaintImage(pictogramValue,Graphics g);
    That's not the way you invoke a method. Step back from graphics and GUI coding and first learn about Passing Information to a Method or a Constructor (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Putting graphics into the run() method.
    By theCardboardBox in forum New To Java
    Replies: 11
    Last Post: 11-17-2010, 06:33 PM
  2. Using Graphics outside of a paint method
    By Catfish1 in forum New To Java
    Replies: 6
    Last Post: 10-26-2010, 08:57 PM
  3. Replies: 5
    Last Post: 10-22-2010, 01:55 PM
  4. Method Graphics.drawString() - Symbol not found
    By km0r3 in forum AWT / Swing
    Replies: 1
    Last Post: 08-27-2010, 02:55 PM
  5. java graphics within main method
    By jforce93 in forum New To Java
    Replies: 4
    Last Post: 02-02-2010, 10:33 PM

Posting Permissions

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