Drawing pictures outside of the paint method
Author |
Message |
ScarletSkyFury
|
Posted: Wed Jun 21, 2006 4:33 pm Post subject: Drawing pictures outside of the paint method |
|
|
I am trying to draw pictures in a method outside the paint method but its giving me an error, it says:
Quote: The name "up" is not a method name but the name of a field member of the type "RPGame"
heres the methods that i am trying to get to draw pictures on the screen:
code: |
public void up (Graphics g)
{
for (int w=0 ; w < 3 ; w++)
{
bufferGraphics.drawImage (screen, 0, 0, 800, 600, this);
x = 500;
y = 500;
y = y + 5;
bufferGraphics.drawImage (up [w], x, y, 50, 50, this);
} //end for loop
} //end up method
public void down (Graphics g)
{
for (int w=0 ; w < 3 ; w++)
{
bufferGraphics.drawImage (screen, 0, 0, 800, 600, this);
x = 500;
y = 500;
y = y - 5;
bufferGraphics.drawImage (down [w], x, y, 50, 50, this);
}
} //end up method
public void left (Graphics g)
{
for (int w=0 ; w < 3 ; w++)
{
bufferGraphics.drawImage (screen, 0, 0, 800, 600, this);
x = 500;
y = 500;
x = x + 5;
bufferGraphics.drawImage (left [w], x, y, 50, 50, this);
}
} //end up method
public void right (Graphics g)
{
for (int w=0 ; w < 3 ; w++)
{
bufferGraphics.drawImage (screen, 0, 0, 800, 600, this);
x = 500;
y = 500;
x = x - 5;
bufferGraphics.drawImage (right [w], x, y, 50, 50, this);
}
} //end up method
|
and this where the errors are coming up:
code: |
if (pressdown == KeyEvent.VK_UP)
up ();<<<<<HERE
else if (pressdown == KeyEvent.VK_DOWN)
down ();<<<<<HERE
else if (pressdown == KeyEvent.VK_RIGHT)
right ();<<<<<HERE
else if (pressdown == KeyEvent.VK_LEFT)
left ();<<<<<HERE
|
any answers? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Wed Jun 21, 2006 4:45 pm Post subject: (No subject) |
|
|
Look at how your methods are defined. Now look at how you're calling them.
If you have not studied the fundamentals of how the Java programming language works, do so before you get too far in trying to create a game, or any other complex program. |
|
|
|
|
|
ScarletSkyFury
|
Posted: Wed Jun 21, 2006 5:23 pm Post subject: (No subject) |
|
|
I put Graphics g in the brackets but then the "g" gets highlighted and pops up with the error:
Quote: Unexpected symbol ignored
what can i do to make those methods work? |
|
|
|
|
|
wtd
|
Posted: Wed Jun 21, 2006 7:08 pm Post subject: (No subject) |
|
|
First off, let's make this properly formatted so we can actually read it. That helps more than I can possibly say.
code: | public void right(Graphics g) {
for (int w = 0; w < 3; w++) {
bufferGraphics.drawImage(screen, 0, 0, 800, 600, this);
x = 500;
y = 500;
x = x - 5;
bufferGraphics.drawImage(right[w], x, y, 50, 50, this);
}
} |
Now... where in this method do you use the parameter "g"? |
|
|
|
|
|
ScarletSkyFury
|
Posted: Wed Jun 21, 2006 7:39 pm Post subject: (No subject) |
|
|
Can you please show me what has to be put inside those brackts to make my methods work and explain it to me why it goes in there so I can learn, I could try and answer and your question but ill just end up making a horrible guess...and sorry I am kinda new to JAVA and dont really understand all its concepts yet(im a turing guy)
thank you |
|
|
|
|
|
wtd
|
Posted: Wed Jun 21, 2006 8:04 pm Post subject: (No subject) |
|
|
ScarletSkyFury wrote: Can you please show me what has to be put inside those brackts to make my methods work and explain it to me why it goes in there so I can learn, I could try and answer and your question but ill just end up making a horrible guess...and sorry I am kinda new to JAVA and dont really understand all its concepts yet(im a turing guy)
You're not using the parameter "g", so your method doesn't really need to accept it, does it? But, if you keep it there, then when you call the method, you have to pass it a Graphics object.
As for being ignorant of Java concepts... correct that. |
|
|
|
|
|
Aziz
|
Posted: Thu Jul 13, 2006 7:58 pm Post subject: (No subject) |
|
|
I think he needs to learn Java first, seems he doesn't really understand the whole concept of passing parameters. |
|
|
|
|
|
TheHobbit
|
Posted: Sun Dec 28, 2008 11:55 pm Post subject: Re: Drawing pictures outside of the paint method |
|
|
i was trying to figure out how to import images into an applet, and i came across this thread,
just trying to learn here too so:
is his mistake not using the parameter g when thats what he calls in his method header ?
should it be
g.drawImage .....
instead of
bufferGraphics.drawImage ....
?
+ im still tryin to figure out a simple way to import images into applet, everything ive come across so far has been usable, but not understandable ( jpanel , bufferdimage , etc )
any help ? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
[Gandalf]
|
Posted: Mon Dec 29, 2008 12:01 am Post subject: Re: Drawing pictures outside of the paint method |
|
|
Locked, please read the rules about necro posting before posting further and start a new topic with your issue afterwards. Thanks. |
|
|
|
|
|
|
|