Home arrow static arrow Java Programming [Archive] - HELP... HELP...HELP...
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - HELP... HELP...HELP...
This topic has 5 replies on 1 page.

Posts:93
Registered: 5/18/04
HELP... HELP...HELP...  
Jul 12, 2004 3:49 AM



 
Hi,

I am developing a java application that can send MMS from PC to handphone. When we want to add the content, we need to do like this:

MMContent s1_text = new MMContent();
byte[] b2 = readFile(path + "HelloWorld.txt");
s1_text.setContent(b2,0,b2.length);
s1_text.setContentId("HelloWorld.txt");
s1_text.setType(IMMConstants.CT_TEXT_PLAIN);
m.addContent(s1_text);

MMContent s1_image = new MMContent();
byte[] b3 = readFile(path + "wiki/./SmileyFace.gif");
s1_image.setContent(b3,0,b3.length);
s1_image.setContentId("wiki/./SmileyFace.gif");
s1_image.setType(IMMConstants.CT_IMAGE_GIF);
m.addContent(s1_image);

MMContent s1_audio = new MMContent();
byte[] b4 = readFile(path + "HelloWorld.amr");
s1_audio.setContent(b4,0,b4.length);
s1_audio.setContentId("HelloWorld.amr");
s1_audio.setType("audio/amr"); //Note how to use mime-types with no pre-defined constant!
m.addContent(s1_audio);

This code will contain 3 contents audio, test and gif file. but this code is done in hardcoded way which mean if we want to add 1 more content, for example a jpg file, we need to add:

MMContent s2_image= new MMContent();
byte[] b5 = readFile(path + "wiki/./sample_image.jpg");
s2_image.setContent(b5,0,b5.length);
s2_image.setContentId("wiki/./sample_image.jpg");
s2_image.setType("IMMConstants.CT_IMAGE_JPG");
m.addContent(s2_image);

which is incovinient for us if we want to do it in a flexible way. so my question is how to do it in the flexible way....
 

Posts:18,384
Registered: 21.03.00
Re: HELP... HELP...HELP...  
Jul 12, 2004 4:21 AM (reply 1 of 5)



 
Hi,

A better way would be:

m.addContents(getContent(path, "HelloWorld.txt", IMMConstants.CT_TEXT_PLAIN));m.addContents(getContent(path, "SmileyFace.gif", IMMConstants.CT_IMAGE_GIF));m.addContents(getContent(path, "HelloWorld.amr", "audio/amr"));m.addContents(getContent(path, "sample_image.jpg", IMMConstants.CT_IMAGE_JPG)); public MMContent getContent(String path, String name, String type) {    byte[] tmp = readFile(path + name);    s2_image.setContent(tmp,0,tmp.length);    s2_image.setContentId(name);    s2_image.setType(type); }


/Kaj
 

Posts:18,384
Registered: 21.03.00
Re: HELP... HELP...HELP...  
Jul 12, 2004 4:23 AM (reply 2 of 5)



 
Sorry,

The method should read:

public MMContent getContent(String path, String name, String type) {    MMContent content = new MMContent();    byte[] tmp = readFile(path + name);    content.setContent(tmp,0,tmp.length);    content.setContentId(name);    content.setType(type);     return content;} 


/Kaj
 

Posts:93
Registered: 5/18/04
Re: HELP... HELP...HELP...  
Jul 12, 2004 7:55 PM (reply 3 of 5)



 
Hi,

thanks for the quick reply...
but if I want to add the

mm.addContent(getContent(path,type));

automatically whenever I want to add the MMS content since I'm going to do the GUI for this application.

Can you help me?
 

Posts:18,384
Registered: 21.03.00
Re: HELP... HELP...HELP...  
Jul 12, 2004 11:26 PM (reply 4 of 5)



 
Hi,

I'm not sure that I understand your question. Just add the available types to a JComboBox, the path to a JTextField, and the filename to another JTextField (or use one single JTextField for both of them). Finally add an ok button. Then when a user clicks ok, read the values from the fields, and call the method I wrote.

/Kaj
 

Posts:93
Registered: 5/18/04
Re: HELP... HELP...HELP...  
Jul 14, 2004 11:01 PM (reply 5 of 5)



 
hehehe.. ok2..
thanks.. I've found the solution...
 
This topic has 5 replies on 1 page.