Activity Stream
48,167 MEMBERS
6819 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 2 of 2
  1.     
    #1
    Member

    Default Some help need in Java programing

    I am trying to make a "jar" program, by using this user can able to send sms from his mobile through way2sms. And they do not need to go to that website. They can instantly send sms from his/her java supported mobile phone. I am almost finished my work. But One file give me headech. I am getting too much error on there. I know their may be small programing mistakes. So peoples please see this codes, I will be very glad if some one fix this codes.


    package hello;

    import java.io.*;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.rms.RecordStore;
    import org.netbeans.microedition.lcdui.SimpleTableModel;
    import org.netbeans.microedition.util.SimpleCancellableTa sk;

    public class HelloMIDlet extends MIDlet
    implements CommandListener
    {

    public HelloMIDlet()
    {
    midletPaused = false;
    rs = null;
    }

    private void initialize()
    {
    }

    public void startMIDlet()
    {
    switchDisplayable(null, getForm1());
    }

    public void resumeMIDlet()
    {
    }

    public void switchDisplayable(Alert alert, Displayable nextDisplayable)
    {
    Display display = getDisplay();
    if(alert == null)
    display.setCurrent(nextDisplayable);
    else
    display.setCurrent(alert, nextDisplayable);
    }

    public void commandAction(Command command, Displayable displayable)
    {
    if(displayable == alert)
    {
    if(command == backCommand)
    {
    textField1.setString("");
    switchDisplayable(null, getForm());
    } else
    if(command == okCommand3)
    switchDisplayable(null, getForm());
    } else
    if(displayable == form)
    {
    if(command == exitCommand)
    {
    switchDisplayable(null, getForm1());
    textField1.setString(null);
    } else
    if(command == okCommand)
    {
    switchDisplayable(null, getMultisms());
    nums.setString(textField.getString());
    } else
    if(command == okCommand1)
    textField1.setString("");
    else
    if(command == okCommand2)
    textField.setString("");
    else
    if(command == screenCommand)
    {
    switchDisplayable(getAlert(), getForm());
    String rlt = null;
    try
    {
    String mob = textField.getString();
    mob = mob.replace('#', ';');
    if(mob.length() > 10 && mob.length() < 15)
    mob = mob.substring(mob.length() - 10);
    stringItem.setText("Sending SMS to " + mob);
    rlt = sendSMS(textField2.getString(), textField3.getString(), mob, textField1.getString());
    }
    catch(IOException ex)
    {
    ex.printStackTrace();
    }
    stringItem.setText(rlt);
    alert.setString(rlt);
    }
    } else
    if(displayable == form1)
    {
    if(command == exitCommand1)
    exitMIDlet();
    else
    if(command == screenCommand1)
    {
    writeRecord(textField2.getString() + ":" + textField3.getString());
    switchDisplayable(null, getForm());
    }
    } else
    if(displayable == form2)
    {
    if(command == exitCommand2 || command != okCommand5);
    } else
    if(displayable == multisms)
    if(command == addCommand)
    {
    String cur = nums.getString();
    String num = cnum.getString();
    if(num.length() < 10)
    {
    switchDisplayable(getAlert1(), getMultisms());
    } else
    {
    num = num.substring(num.length() - 10);
    if(num.length() == 10)
    {
    if(cur.equals(""))
    cur = cur + num;
    else
    cur = cur + "#" + num;
    nums.setString(cur);
    cnum.setString("");
    } else
    {
    switchDisplayable(getAlert1(), getMultisms());
    }
    }
    } else
    if(command == doneCommand)
    {
    textField.setString(nums.getString());
    nums.setString("");
    switchDisplayable(null, getForm());
    } else
    if(command == okCommand4)
    nums.setString("");
    }

    public Command getExitCommand()
    {
    if(exitCommand == null)
    exitCommand = new Command("Logout", 4, 4);
    return exitCommand;
    }

    public Form getForm()
    {
    if(form == null)
    {
    form = new Form("SMS Programed by Bapi Dey", new Item[] {
    getTextField(), getTextField1(), getStringItem()
    });
    form.addCommand(getExitCommand());
    form.addCommand(getScreenCommand());
    form.addCommand(getOkCommand());
    form.addCommand(getOkCommand1());
    form.addCommand(getOkCommand2());
    form.setCommandListener(this);
    }
    return form;
    }

    public Command getScreenCommand()
    {
    if(screenCommand == null)
    screenCommand = new Command("Send", 2, 0);
    return screenCommand;
    }

    public TextField getTextField()
    {
    if(textField == null)
    textField = new TextField("Mobile No", null, 600, 3);
    return textField;
    }

    public TextField getTextField1()
    {
    if(textField1 == null)
    {
    textField1 = new TextField("Msg", null, 140, 0);
    textField1.setLayout(0);
    textField1.setPreferredSize(-1, 120);
    }
    return textField1;
    }

    public Alert getAlert()
    {
    if(alert == null)
    {
    alert = new Alert("alert", null, getImage1(), null);
    alert.addCommand(getBackCommand());
    alert.addCommand(getOkCommand3());
    alert.setCommandListener(this);
    alert.setTimeout(-2);
    }
    return alert;
    }

    public StringItem getStringItem()
    {
    if(stringItem == null)
    {
    stringItem = new StringItem("", "140 Characters Remainig");
    stringItem.setFont(getFont1());
    }
    return stringItem;
    }

    public Command getExitCommand1()
    {
    if(exitCommand1 == null)
    exitCommand1 = new Command("Exit", 7, 0);
    return exitCommand1;
    }

    public Command getScreenCommand1()
    {
    if(screenCommand1 == null)
    screenCommand1 = new Command("Login", 1, 0);
    return screenCommand1;
    }

    public Form getForm1()
    {
    if(form1 == null)
    {
    form1 = new Form("Login", new Item[] {
    getImageItem(), getTextField2(), getTextField3(), getSpacer(), getStringItem1()
    });
    form1.addCommand(getExitCommand1());
    form1.addCommand(getScreenCommand1());
    form1.setCommandListener(this);
    openRecStore();
    String str = readRecords();
    String uid = null;
    String pwd = null;
    if(str != null)
    {
    uid = str.substring(0, str.indexOf(":"));
    pwd = str.substring(str.indexOf(":") + 1);
    textField2.setString(uid);
    textField3.setString(pwd);
    }
    }
    return form1;
    }

    public TextField getTextField2()
    {
    if(textField2 == null)
    {
    textField2 = new TextField("Mobile", null, 32, 2);
    textField2.setInitialInputMode("UCB_BASIC_LATIN");
    }
    return textField2;
    }

    public TextField getTextField3()
    {
    if(textField3 == null)
    textField3 = new TextField("Password", null, 32, 0x10000);
    return textField3;
    }

    public Font getFont1()
    {
    if(font1 == null)
    font1 = Font.getFont(0, 0, 8);
    return font1;
    }

    public StringItem getStringItem1()
    {
    if(stringItem1 == null)
    {
    stringItem1 = new StringItem("Software Developed By", "Bapi Dey (bapi@sobarforum.com) Visit sobarforum.com Get latest Movies, Musics, Softwares", 1);
    stringItem1.setFont(getFont1());
    }
    return stringItem1;
    }

    public Spacer getSpacer()
    {
    if(spacer == null)
    {
    spacer = new Spacer(16, 1);
    spacer.setPreferredSize(-1, 30);
    }
    return spacer;
    }

    public SimpleCancellableTask getTask()
    {
    if(task == null)
    {
    task = new SimpleCancellableTask();
    task.setExecutable(new Object() /* anonymous class not found */
    class _anm1 {}

    );
    }
    return task;
    }

    public Command getBackCommand()
    {
    if(backCommand == null)
    backCommand = new Command("Clear Msg", 2, 0);
    return backCommand;
    }

    public Form getMultisms()
    {
    if(multisms == null)
    {
    multisms = new Form("Select Multiple Sender", new Item[] {
    getCnum(), getNums()
    });
    multisms.addCommand(getDoneCommand());
    multisms.addCommand(getAddCommand());
    multisms.addCommand(getOkCommand4());
    multisms.setCommandListener(this);
    }
    return multisms;
    }

    public TextField getNums()
    {
    if(nums == null)
    {
    nums = new TextField("Multiple Senders(# to seperate)", null, 600, 3);
    nums.setPreferredSize(-1, 220);
    }
    return nums;
    }

    public Command getOkCommand()
    {
    if(okCommand == null)
    okCommand = new Command("MultiSender", 4, 1);
    return okCommand;
    }

    public Command getOkCommand1()
    {
    if(okCommand1 == null)
    okCommand1 = new Command("Clear Msg", 4, 2);
    return okCommand1;
    }

    public TextField getCnum()
    {
    if(cnum == null)
    cnum = new TextField("Select From Contact", null, 32, 3);
    return cnum;
    }

    public Command getDoneCommand()
    {
    if(doneCommand == null)
    doneCommand = new Command("Done", 4, 0);
    return doneCommand;
    }

    public Command getAddCommand()
    {
    if(addCommand == null)
    addCommand = new Command("Add Number", 2, 0);
    return addCommand;
    }

    public Alert getAlert1()
    {
    if(alert1 == null)
    {
    alert1 = new Alert("!!!Warning!!!", "Plz Provide a 10 Digit Number", null, AlertType.WARNING);
    alert1.setTimeout(-2);
    }
    return alert1;
    }

    public Command getOkCommand2()
    {
    if(okCommand2 == null)
    okCommand2 = new Command("Clear Numbers", 4, 3);
    return okCommand2;
    }

    public Command getOkCommand3()
    {
    if(okCommand3 == null)
    okCommand3 = new Command("Done", 4, 0);
    return okCommand3;
    }

    public Command getOkCommand4()
    {
    if(okCommand4 == null)
    okCommand4 = new Command("Clear Numbers", 4, 0);
    return okCommand4;
    }

    public Form getForm2()
    {
    if(form2 == null)
    {
    form2 = new Form("form2", new Item[] {
    getTextField4(), getObject()
    });
    form2.addCommand(getOkCommand5());
    form2.addCommand(getExitCommand2());
    form2.setCommandListener(this);
    }
    return form2;
    }

    public SimpleTableModel getTableModel()
    {
    if(tableModel == null)
    tableModel = new SimpleTableModel((String[][])null, null);
    return tableModel;
    }

    public TextField getTextField4()
    {
    if(textField4 == null)
    {
    textField4 = new TextField("Provide 10 Digit Mobile Number", null, 32, 0);
    textField4.setPreferredSize(-1, 80);
    }
    return textField4;
    }

    public TextField getObject()
    {
    if(object == null)
    {
    object = new TextField("Look Up Details", null, 32, 0);
    object.setPreferredSize(-1, 140);
    }
    return object;
    }

    public Command getOkCommand5()
    {
    if(okCommand5 == null)
    okCommand5 = new Command("Get", 4, 0);
    return okCommand5;
    }

    public Command getExitCommand2()
    {
    if(exitCommand2 == null)
    exitCommand2 = new Command("Exit", 7, 0);
    return exitCommand2;
    }

    public Image getImage1()
    {
    if(image1 == null)
    try
    {
    image1 = Image.createImage("/sms-big.gif");
    }
    catch(IOException e)
    {
    e.printStackTrace();
    }
    return image1;
    }

    public ImageItem getImageItem()
    {
    if(imageItem == null)
    imageItem = new ImageItem("", getImage2(), 0, "<Missing Image>", 0);
    return imageItem;
    }

    public Image getImage2()
    {
    if(image2 == null)
    try
    {
    image2 = Image.createImage("/way2sms.gif");
    }
    catch(IOException e)
    {
    e.printStackTrace();
    }
    return image2;
    }

    public Display getDisplay()
    {
    return Display.getDisplay(this);
    }

    public void exitMIDlet()
    {
    switchDisplayable(null, null);
    destroyApp(true);
    notifyDestroyed();
    }

    public void startApp()
    {
    if(midletPaused)
    {
    resumeMIDlet();
    } else
    {
    initialize();
    startMIDlet();
    }
    midletPaused = false;
    }

    public void pauseApp()
    {
    midletPaused = true;
    }

    public void destroyApp(boolean flag)
    {
    }

    public static String sendSMS(String uid, String pwd, String mob, String msg)
    throws IOException
    {
    HttpConnection httpConn;
    String url;
    InputStream is;
    OutputStream os;
    String out;
    httpConn = null;
    url = "http://demo.samplephpcodes.com/sms/way2sms.php?uid=" + uid + "&pwd=" + pwd;
    is = null;
    os = null;
    out = "";
    url = url + "&phone=" + mob + "&msg=" + urlEncode(msg);
    httpConn = (HttpConnection)Connector.open(url);
    httpConn.setRequestMethod("GET");
    httpConn.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    getConnectionInformation(httpConn);
    int respCode = httpConn.getResponseCode();
    httpConn;
    if(respCode == 200)
    {
    StringBuffer sb = new StringBuffer();
    os = httpConn.openOutputStream();
    is = httpConn.openDataInputStream();
    int chr;
    while((chr = is.read()) != -1)
    sb.append((char)chr);
    System.out.println("Status" + sb.toString());
    out = sb.toString();
    } else
    {
    System.out.println("Error in opening HTTP Connection. Error#" + respCode);
    }
    if(is != null)
    is.close();
    if(os != null)
    os.close();
    if(httpConn != null)
    httpConn.close();
    break MISSING_BLOCK_LABEL_324;
    Exception exception;
    exception;
    if(is != null)
    is.close();
    if(os != null)
    os.close();
    if(httpConn != null)
    httpConn.close();
    throw exception;
    return out;
    }

    public static String urlEncode(String s)
    {
    if(s == null)
    return s;
    StringBuffer sb;
    sb = new StringBuffer(100);
    for(int i = 0; i < s.length(); i++)
    {
    char c = s.charAt(i);
    if(c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z')
    {
    sb.append(c);
    continue;
    }
    if(c > '\017')
    sb.append("%" + Integer.toHexString(c));
    else
    sb.append("%0" + Integer.toHexString(c));
    }

    return sb.toString();
    Exception ex;
    ex;
    System.out.println("Exception, URLencode string is " + s);
    return null;
    }

    public static void getConnectionInformation(HttpConnection httpconnection)
    {
    }

    public void openRecStore()
    {
    try
    {
    rs = RecordStore.openRecordStore("ReadWriteRMS", true);
    }
    catch(Exception e) { }
    }

    public void closeRecStore()
    {
    try
    {
    rs.closeRecordStore();
    }
    catch(Exception e) { }
    }

    public void deleteRecStore()
    {
    if(RecordStore.listRecordStores() != null)
    try
    {
    RecordStore.deleteRecordStore("ReadWriteRMS");
    }
    catch(Exception e) { }
    }

    public void writeRecord(String str)
    {
    byte rec[] = str.getBytes();
    try
    {
    rs.addRecord(rec, 0, rec.length);
    }
    catch(Exception e) { }
    }

    public String readRecords()
    {
    String ret = null;
    try
    {
    byte recData[] = new byte[5];
    for(int i = 1; i <= rs.getNumRecords(); i++)
    {
    if(rs.getRecordSize(i) > recData.length)
    recData = new byte[rs.getRecordSize(i)];
    int len = rs.getRecord(i, recData, 0);
    ret = new String(recData, 0, len);
    }

    }
    catch(Exception e) { }
    return ret;
    }

    private boolean midletPaused;
    private RecordStore rs;
    static final String REC_STORE = "ReadWriteRMS";
    private Command exitCommand;
    private Command screenCommand;
    private Command screenCommand1;
    private Command exitCommand1;
    private Command backCommand;
    private Command okCommand;
    private Command okCommand1;
    private Command addCommand;
    private Command doneCommand;
    private Command okCommand4;
    private Command okCommand2;
    private Command okCommand3;
    private Command okCommand5;
    private Command exitCommand2;
    private Form form;
    private TextField textField1;
    private TextField textField;
    private StringItem stringItem;
    private Alert alert;
    private Form form1;
    private TextField textField2;
    private TextField textField3;
    private StringItem stringItem1;
    private Spacer spacer;
    private ImageItem imageItem;
    private Form multisms;
    private TextField cnum;
    private TextField nums;
    private Alert alert1;
    private Form form2;
    private TextField textField4;
    private TextField object;
    private Font font1;
    private SimpleCancellableTask task;
    private SimpleTableModel tableModel;
    private Image image2;
    private Image image1;




    }
    bapi21 Reviewed by bapi21 on . Some help need in Java programing I am trying to make a "jar" program, by using this user can able to send sms from his mobile through way2sms. And they do not need to go to that website. They can instantly send sms from his/her java supported mobile phone. I am almost finished my work. But One file give me headech. I am getting too much error on there. I know their may be small programing mistakes. So peoples please see this codes, I will be very glad if some one fix this codes. Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Is it no one here who can solve this? Its strange

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Java stinks: Turn off your Java browser plugin
    By Loget in forum General Discussion
    Replies: 37
    Last Post: 5th Sep 2012, 07:40 AM
  2. Programing services
    By dropboks in forum Completed Transactions
    Replies: 0
    Last Post: 11th Mar 2012, 08:16 PM
  3. what programing language needed to code a bot
    By YOUSEFN in forum General Discussion
    Replies: 1
    Last Post: 25th Jan 2012, 04:16 PM
  4. Anyone Who Knows PHP Programing
    By Tigger in forum Web Development Area
    Replies: 7
    Last Post: 21st Jan 2011, 06:53 PM
  5. TCP / Ip programing ?
    By CatchItBaby in forum Web Development Area
    Replies: 2
    Last Post: 8th Jul 2010, 02:38 PM

Tags for this Thread

BE SOCIAL