Results 1 to 1 of 1
Thread: Showing Images with J2ME
- 06-18-2007, 10:39 AM #1
Member
- Join Date
- May 2007
- Posts
- 11
- Rep Power
- 0
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);
}
}
Similar Threads
-
Need Help showing text in JTextArea
By GuyFawkes in forum AWT / SwingReplies: 3Last Post: 05-05-2008, 09:19 AM -
Error Messages Not Showing Up
By nvidia in forum Web FrameworksReplies: 0Last Post: 04-07-2008, 10:41 PM -
J2me
By kuttyniti@gmail.com in forum Sun Java Wireless ToolkitReplies: 0Last Post: 11-24-2007, 06:27 AM -
Assert - not showing any msg on console
By ravian in forum New To JavaReplies: 0Last Post: 11-16-2007, 03:20 PM -
Why isn't this showing?
By JToolTip in forum Java AppletsReplies: 2Last Post: 07-07-2007, 11:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks