{Java} A lill Help

01/11/2012 09:42 Keyeight#1
hi guys well im start learning Java scripting and to start i make a simple 2d game but im stuck at the part of it and i hope some one can help for that i know it`s not about Sro but i learn it to get some skill`s to make somthing for Sro by Java script this is my code
Code:
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class GameFrame extends JPanel{
	public GameFrame() {
		setFocusable(true);
	}
	public void paint(Graphics g) {
		super.paint(g);
		Graphics2D g2d = (Graphics2D)g;
		g2d.drawString("Hello ESFA ", 150, 100);
		ImageIcon ic = new ImageIcon("C:/New Folder/Player.PNG");
		Image i= ic.getImage();
		g2d.drawImage(i, 500, 200, null);
		
	}

}
when i call the image it dont appear it just open the frame and the title that`s it

here the full code

Code:
import javax.swing.JFrame;


public class ESFA {

	public static void main(String[] args) {
		JFrame frame=new JFrame("ESFA Game");
		frame.setSize(800,600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		frame.add(new GameFrame());
		frame.setVisible(true);
		
		
		
	}

}

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class GameFrame extends JPanel{
	public GameFrame() {
		setFocusable(true);
	}
	public void paint(Graphics g) {
		super.paint(g);
		Graphics2D g2d = (Graphics2D)g;
		g2d.drawString("Hello ESFA ", 150, 100);
		ImageIcon ic = new ImageIcon("C:/New Folder/Player.PNG");
		Image i= ic.getImage();
		g2d.drawImage(i, 500, 200, null);
		
	}

}
best regards
mats0o0o0
01/11/2012 18:37 Schickl#2
Use backslash instead of slashs!
Some classes can parse it, but I'm not too sure about this one
So give it a try

edit: Ok the javadoc even suggests to use slashes
try to use a relative path and if that doesn't work debug it(the ImageIcon constructor doesn't throw an exception when the image can't be found so debugging it might help to detect the problem)
I suggest you Netbeans([Only registered and activated users can see links. Click Here To Register...]). it has a nice debugger and many features
01/12/2012 00:37 Little Hole#3
your code is completely right just be sure that you put the image in the dir
C:\new folder\player.png
and be sure this file player.png is an image file !!!

or change the code from

ImageIcon ic = new ImageIcon("C:/New Folder/Player.PNG");

to
ImageIcon ic = new ImageIcon("Player.PNG");

and put the file Player.png in the same folder as your java file is if you use jcreator
or in the bin,or dest i don't remember correctly (btw in the dir that your app is running) folder if you use netbeans
hope to help
01/12/2012 13:31 Keyeight#4
thx alot guys this comment`s really helped me alot and it`s working perfect right now and i complete my code`s and it`s working with out any bugs if you wanna the code`s just till me

now i will start to work on 3d game not 2d

then i will start to make my frist Java bot for silkroad and it will be for free