Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-18-2007, 11:39 AM
Member
 
Join Date: May 2007
Posts: 11
luisarca is on a distinguished road
Showing Images with J2ME
Hi to all,

I'm doing a new class that contains a two method to show pictures. I'm using Apache, the web server program, and my application has to connect with Apache(by localhost), to download the pictures I have placed in folder "htdocs" of Apache. But the program doesn't work. Apparently, but I'm not sure, there is not connection between the program and the webpage.
I send you here the code, and maybe someone can help me.

Thank you very much,

Luisarca

Program:

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.Vector;




class mostrarfotos extends Canvas
{

private int width;
private int height;
private Image img;
private HttpConnection c;
Display display=null;
Form form=null;
mostrarfotos(String nombrefoto)
{
width = getWidth();
height = getHeight();
// Load the graphics
String url = "http://localhost/" + nombrefoto;
System.err.println(url);
DataInputStream is = null;
StringBuffer sb = new StringBuffer();
img=null;

try
{
c =(HttpConnection) Connector.open(url);
c.setRequestProperty("Content-Language","es-ES");
c.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
c.setRequestProperty("Connection","close");
c.setRequestMethod(HttpConnection.GET);
int len = (int)c.getLength();
System.err.println("aqui ya no llego /n");
if (len > 0)
{
is = c.openDataInputStream();
byte[] data = new byte[len];
is.readFully(data);
img = Image.createImage(data, 0, len);
}
else
{
showAlert("length is null");;
}
is.close();
c.close();
}
catch (Exception e)
{
System.err.println("Problem loading image ");
e.printStackTrace();
showAlert(e.getMessage());
}
}

/* Display Error On screen*/
private void showAlert(String err)
{
Alert a = new Alert("");
a.setString(err);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a);
}



public void paint(Graphics g)
{

//Paint a white background
g.setColor( 0, 0, 0 );
g.fillRect( 0, 0, getWidth(), getHeight() );
g.setColor( 255, 255, 255);
// Paint the sprite
g.drawImage(img,0,0,Graphics.TOP|Graphics.LEFT);
}


}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help showing text in JTextArea GuyFawkes AWT / Swing 3 05-05-2008 10:19 AM
Error Messages Not Showing Up nvidia Web Frameworks 0 04-07-2008 11:41 PM
J2me kuttyniti@gmail.com Sun Java Wireless Toolkit 0 11-24-2007 07:27 AM
Assert - not showing any msg on console ravian New To Java 0 11-16-2007 04:20 PM
Why isn't this showing? JToolTip Java Applets 2 07-08-2007 12:54 AM


All times are GMT +3. The time now is 08:36 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org