PDA

View Full Version : Help with paint pictures into java


powerpuff
12-25-2006, 07:41 PM
Hello,
I am current creating a video game for a semester end project.
I was wondering how you would get a picture online and put it into paint and then translating to java with some codes? is there a website i should look at because i can't find anything about it?
My second question, if i know how to paste the pictures into java, should i put the pictures in any certain coordinates?
My third question, can i just put everything in the same file and not creating multiple files, will it affect me in any way? Teachers always said to put it in several files so that in can compile faster, but how much faster because i don't know how to do it : (. Thanks for your time to read my need of help. Thanks for the assisstance.

powerpuff
12-26-2006, 04:29 PM
no reply : (

Gox
12-27-2006, 01:38 AM
I assume most people are enjoying the holidays, and are spending more time with friends and family then on the forums.

Based on your post I'll first ask, How much Java do you know? I have a feeling your programming background is minimal, in which case I would suggest learning Java more thoroughly before attempting to create a game.

powerpuff
12-27-2006, 04:07 PM
I know how to do:
-placing background in a gbuffer (virtual memory) thing so it won't flicker
-calling my paint methods from the public void head(Graphics g){} , head(g);
-animation moving the person left, right, up, down etc.
-so yea, i'm limited with methods and knowledge about computer science, however i look stuff up if i don't know what i'm doing.
Thanks for reading my post : )

daniel_g
12-27-2006, 09:15 PM
My third question, can i just put everything in the same file and not creating multiple files, will it affect me in any way? Teachers always said to put it in several files so that in can compile faster, but how much faster because i don't know how to do it : (. Thanks for your time to read my need of help. Thanks for the assisstance.
Not really, as long as the program works, unless your professor is really strick, you should be fine. The main reason they ask you to put it on several files, is because then it's easier to read that way, so if there is something not working they will usually be able to tell what it is.

Also, in the future, if you ever work on a big project, you migth be required to work on only some parts of the project, while other people work on the other parts. So it's actually helpfull to learn how to do it.

Anyways, here is how you usually separate classes. Suppose you had the following class:

public class SingleClass{
public static int a, b, c;
public static void main(String[] args){
a = 1;
b = 2;
c = a+b;
System.out.println(c);
// and down here some other operations that require the value of c
// and some additional stuff that will make the class look messy..
}// end main
}// end SingleClass

You can translate it into:

public class Class1{
public static int a, b, c;

public int method1(){
a = 1;
b = 2;
c = a+b;
return c;
}//end method1
}//end Class1


public class Class2{
public static int c;

public static void main(String[] args){
Class1 value = new Class1();
System.out.println(value.method1());
c = value.method1();
// and down here some other operations that require the value of c
// you can put the additional stuff here, or even in some other class.
// It will help your Class1 look less messy.
}//end main
}//end Class2

daniel_g
12-27-2006, 11:51 PM
Regarding your second question, yeah, you would need to use a coordinate system. If you wanted the image to move arround, just update the coordinates and use repaint() method. Here's an example I got from my book:

up = new ImageIcon("arrowUp.gif");
down = new ImgageIcon("arrowDown.gif")

public void keyPressed(KeyEvent event){
switch(event.getKeyCode()){

case KeyEvent.VK_UP:
currentImage = up; //tells java you want to use arrowUp.gif
y -= 10; //move image 10 pixels up. Note java 'y' coordinate is upside down
break;

caseKeyEvent.VK_DOWN:
currentImage = down; //tells java you want to use arrowDown.gif
y += 10; //move image 10 pixels down
break;
}
repaint();
}


I personally don't think it's a good idea to get the pictures off the internet. But if you really need to, you can read this tutorial:
http://java.sun.com/docs/books/tutorial/networking/overview/alreadyknow.html
Read the part where it says "Loading Images from URLs", and click the appropiate links.

powerpuff
12-29-2006, 04:44 PM
hmmm is there a link where i load pictures from the internet into the Paint program, then translate it to the java code? because i'm not taking the link from the internet directly. Or is it the same concept that i have to create an applet link of the picture i placed from the internet to the Paint program. (The Paint program refers to, Start, all Programs, Accessories, then Paint on the toolbar.) Anytime i would like to use something from the internet ill refer to that site : D thanks xD

daniel_g
12-30-2006, 03:35 AM
I'm not sure what you mean.
Are you saying that you, will be downloading the pictures off the internet, I mean, like you will rigth click it, click save as, then open it on paint and modify it, and after that you want to put the picture in your game? Or do you want a sample code that will do all that for you? Or do you need something different from what I just said?

powerpuff
12-30-2006, 04:17 PM
i'm not really sure. I saw this person in class download the picture on the internet and place it on the paint program as a pixeled picture. So, then he would read it from java, and finally it would appear on the applet screen. I don't need it from the internet because i might need to change some pictures up, maybe add more pictures, that's why i use the paint program.
So it's, pretty much what you said that sentence putting it into a game from paint. But, inorder to put it into game, i need to put it into java code don't i?

daniel_g
12-31-2006, 07:50 AM
The image you are going to use must be saved on the hard drive. Of course, you can use a program like paint to edit it, but changes wont take effect until the image is saved again, and reloaded on java.

I'm not sure if you can actually transform an existing image into code(maybe serializing it?). What I'm trying to say is that you migth actually have to take the image files(jpg, bmp, gif, etc) everywhere you want them to work.

Use this link:
http://www.webkinesia.com/online/oop/notes/java3.php
Scroll down to keyEvents(that's the second event). They give a pretty good example on how to use images stored on your hard drive(Direction.java and DirectionPanel.java).

powerpuff
01-09-2007, 05:25 AM
Thanks Mr. Daniel_g, however, i found the word i was looking for, sprites*, relating to the sprite topic, hard-coding the codes into java could be a pain... however, there is a way to import it, i was wondering what site could tell me about the import of sprites or pretty much the sprite topic. A majority of the sites explain about sprites itself, but i can't find one desirable with importing sprites. And if i found one, i can't follow through the program.