Register for your free account! | Forgot your password?

You last visited: Today at 01:04

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



{Java} A lill Help

Discussion on {Java} A lill Help within the SRO Coding Corner forum part of the Silkroad Online category.

Reply
 
Old   #1
 
Keyeight's Avatar
 
elite*gold: 844
Join Date: Oct 2010
Posts: 839
Received Thanks: 192
{Java} A lill Help

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 ****** 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
Keyeight is offline  
Old 01/11/2012, 18:37   #2
 
Schickl's Avatar
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,064
Received Thanks: 539
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(). it has a nice debugger and many features
Schickl is offline  
Thanks
1 User
Old 01/12/2012, 00:37   #3
 
elite*gold: 0
Join Date: Jul 2011
Posts: 31
Received Thanks: 5
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
Little Hole is offline  
Thanks
1 User
Old 01/12/2012, 13:31   #4
 
Keyeight's Avatar
 
elite*gold: 844
Join Date: Oct 2010
Posts: 839
Received Thanks: 192
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
Keyeight is offline  
Reply


Similar Threads Similar Threads
[JAVA Error] Could not create the java virtual machine
07/21/2013 - Technical Support - 10 Replies
Schönen Abend! Leider hat es sich aus einem unerfindlichen Grund ergeben, dass sobald ich die Minecraft.exe starten will die Errormeldung kommt. Die Tips auf Minecraft.net habe ich schon ohne Erfolg befolgt. Hoffe ihr könnt mir weiterhelfen... Mein PC:
[Java] Could not create the Java virtual machine
06/22/2011 - Minecraft - 1 Replies
hallo ihr minecraftler ^^ habe seit heute das problem das wenn ich minecraft starte original als auch cracked das diese fehlermeldung kommt: Java virtual machine Launcher Could not create the Java virtual machine



All times are GMT +2. The time now is 01:04.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.