11 Replies - 4580 Views - Last Post: 21 March 2010 - 10:56 PM

#1 dreamluver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-January 09

Cannot display images in J2ME

Posted 28 July 2009 - 08:03 AM

hey guys...for creating tiles for use in a tiled layer on j2me what can i use and preferably what kind of format should it be in? cause my teacher told me its best in png form but after making a tile using paint the png file cant be loaded when the canvas is completed..any help given is much appreciated...in addition i've been having abit of difficulty with the part on filling the layer.the codes are shown below..the filling layer part was done lke an example as i was unsure what to put in there..please help

import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;

public class MyGameCanvas extends GameCanvas implements Runnable {
		ChessGame midlet;
		boolean initialized = false;
		Thread thread;
		LayerManager layermanager;
	public MyGameCanvas(ChessGame midlet) {
		super(true);
		this.midlet = midlet;
	}
  public void initialize() {
		layermanager = new LayerManager();
		Image Chessboard;
		TiledLayer Black;
		TiledLayer Green;


		int[] Black_cells = new int[]{
			1, 0, 1, 0, 1, 0, 1, 0,
			0, 1, 0, 1, 0, 1, 0, 1,
			1, 0, 1, 0, 1, 0, 1, 0,
			0, 1, 0, 1, 0, 1, 0, 1,
			1, 0, 1, 0, 1, 0, 1, 0,
			0, 1, 0, 1, 0, 1, 0, 1,
			1, 0, 1, 0, 1, 0, 1, 0,
			0, 1, 0, 1, 0, 1, 0, 1,
		 };
		 int[] Green_cells = new int[]{
			0, 2, 0, 2, 0, 2, 0, 2,
			2, 0, 2, 0, 2, 0, 2, 0,
			0, 2, 0, 2, 0, 2, 0, 2,
			2, 0, 2, 0, 2, 0, 2, 0,
			0, 2, 0, 2, 0, 2, 0, 2,
			2, 0, 2, 0, 2, 0, 2, 0,
			0, 2, 0, 2, 0, 2, 0, 2,
			2, 0, 2, 0, 2, 0, 2, 0,
		 };
					try {
			 Chessboard = Image.createImage("/board.png");
			 Black = new TiledLayer(8, 8, Chessboard, 48, 48);
			 fillLayer(Black, Black_cells);
			 Green = new TiledLayer(8, 8, Chessboard, 48,48);
			 fillLayer(Green, Green_cells);
			 layermanager.append(Black);
			 layermanager.append(Green);
}
		 catch (Exception ex) {
			System.out.println("Image loading error!");
		}

  }
   private void drawDisplay(Graphics g) {
		g.setColor(0xffffff);
		g.fillRect(0, 0, getWidth(), getHeight());
		 layermanager.paint(g, 0, 0);
			flushGraphics();
   }

   public void startThread() {
	  initialize();
		initialized = true;
		thread = new Thread();
		thread.start();
	}
	public void stopThread() {
		initialized = false;
	}
		private void fillLayer(TiledLayer layer, int[] cells){
			 for (int row = 0; row < layer.getRows(); row++) {
			for (int col = 0; col < layer.getColumns(); col++) {
				layer.setCell(col, row, cells[row * layer.getColumns() + col]);
			}
		}
	}
	 
	public void run(){
Graphics g =getGraphics();
while (initialized){
drawDisplay(g);
}
	}



}





Is This A Good Question/Topic? 0
  • +

Replies To: Cannot display images in J2ME

#2 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Cannot display images in J2ME

Posted 28 July 2009 - 09:57 AM

Don't use paint to modify images.
Download Paint.NET and use that instead.

What's wrong with the code? Could you post a screenshot?
Was This Post Helpful? 0
  • +
  • -

#3 dreamluver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-January 09

Re: Cannot display images in J2ME

Posted 28 July 2009 - 09:23 PM

View Postborn2c0de, on 28 Jul, 2009 - 08:57 AM, said:

Don't use paint to modify images.
Download Paint.NET and use that instead.

What's wrong with the code? Could you post a screenshot?



there was nth wrong with the coding i should say but more there is a problem loading the image
Was This Post Helpful? 0
  • +
  • -

#4 dreamluver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-January 09

Re: Cannot display images in J2ME

Posted 28 July 2009 - 11:31 PM

View Postdreamluver, on 28 Jul, 2009 - 08:23 PM, said:

View Postborn2c0de, on 28 Jul, 2009 - 08:57 AM, said:

Don't use paint to modify images.
Download Paint.NET and use that instead.

What's wrong with the code? Could you post a screenshot?



there was nth wrong with the coding i should say but more there is a problem loading the image



ahh i've changed the picture but still thers nth showing..although it says build successful just that when i run the emulator nth comes up
Was This Post Helpful? 0
  • +
  • -

#5 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Cannot display images in J2ME

Posted 29 July 2009 - 12:42 PM

Chessboard = Image.createImage("/board.png");

When you save a png file in MS Paint, the extension is saved as "PNG" by default.
Since J2ME is case-sensitive, change the above statement to this:
Chessboard = Image.createImage("/board.PNG");


That should do the trick.

(Topic Title Changed to be more descriptive)
Was This Post Helpful? 0
  • +
  • -

#6 dreamluver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-January 09

Re: Cannot display images in J2ME

Posted 01 August 2009 - 12:18 AM

View Postborn2c0de, on 29 Jul, 2009 - 11:42 AM, said:

Chessboard = Image.createImage("/board.png");

When you save a png file in MS Paint, the extension is saved as "PNG" by default.
Since J2ME is case-sensitive, change the above statement to this:
Chessboard = Image.createImage("/board.PNG");


That should do the trick.

(Topic Title Changed to be more descriptive)


it still doesn work eh=o how??
Was This Post Helpful? 0
  • +
  • -

#7 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Cannot display images in J2ME

Posted 02 August 2009 - 03:05 AM

Could you attach the JAR file with you next post?
I'll have a look at it.
Please compile the application WITHOUT optimization and WITH Debugging Info as it'll make it easier for me to analyze your application.
Was This Post Helpful? 0
  • +
  • -

#8 dreamluver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-January 09

Re: Cannot display images in J2ME

Posted 02 August 2009 - 04:25 AM

View Postborn2c0de, on 2 Aug, 2009 - 02:05 AM, said:

Could you attach the JAR file with you next post?
I'll have a look at it.
Please compile the application WITHOUT optimization and WITH Debugging Info as it'll make it easier for me to analyze your application.



it says i cant attach files with that kinda extension
Was This Post Helpful? 0
  • +
  • -

#9 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Cannot display images in J2ME

Posted 03 August 2009 - 04:14 AM

Add the JAR file in a ZIP/RAR archive and attach it.
If you can, also include the source code in the archive.
Was This Post Helpful? 0
  • +
  • -

#10 dreamluver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-January 09

Re: Cannot display images in J2ME

Posted 04 August 2009 - 12:06 AM

View Postborn2c0de, on 3 Aug, 2009 - 03:14 AM, said:

Add the JAR file in a ZIP/RAR archive and attach it.
If you can, also include the source code in the archive.


hahas..its oki dude..i solved the problem..seems lke it was my own fault..although it wasn an error in the codes but something was missing causing the programme to keep looping..thanks aniways^^ hees..thread closed i guess=)
Was This Post Helpful? 0
  • +
  • -

#11 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Cannot display images in J2ME

Posted 04 August 2009 - 03:50 AM

lol, glad to hear you solved your problem.
Was This Post Helpful? 0
  • +
  • -

#12 Guest_MRINMOY CHATTOPADHYAY*


Reputation:

Re: Cannot display images in J2ME

Posted 21 March 2010 - 10:56 PM

How to show images one by one in j2me........
Was This Post Helpful? 0

Page 1 of 1