It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

News

Log In Sponsors
Partner Sites
quality india phone card at phonecardsavenue
hobo handbags No fake items. All Authentic!

ThatBigForum

Please go through this and tell me to how to reduce the CPU



[code:1bfepuzv]import java.io.*;
import java.util.*;
import javax.comm.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Send_SMS
{
public ListenPort listenPort;
/*
* Send_SMS constructor creates an object for Gui class
*/
public Send_SMS()
{
//Gui g=new Gui();
//ListenPort lp = new ListenPort();
StartupForm sf=new StartupForm();
}
/*
* main method creates an object for Send_SMS class
*/
public static void main(String args[])
{
StartupForm sf=new StartupForm();

//ListenPort lp=new ListenPort();
//lp.start();
//Send_SMS sendSMS=new Send_SMS();
}
}
/*
* class ListenPort gets the properties of thread and initiates
* the serial port listener to handle the data on serial port using
* its methods
* @version 1.0
* @author Sasi krishna and Deepthi
* @Date 02-02-2007
*/
class ListenPort extends Thread implements SerialPortEventListener {
//static Enumeration portList;
static CommPortIdentifier portId;
static String messageString;
static SerialPort serialPort;
static OutputStream outputStream;
static InputStream inputStream;
static boolean outputBufferEmptyFlag = false;
static Thread readThread;
private javax.swing.Timer timerTimeOut;
private byte[] globalBuffer;
private int MAXLOC=0;
private boolean completeInfo=false;
private int index=0,ACK=0;
private String msg1=new String();
private Vector intSmsBuf,intSmsBuf2;
private RequestSMS reqSMS;

private Connection con;
private ResultSet rs;
private Statement stmt;
private String query;
private int msgType=-1;
private int flag = 0;

/*
* run method
* 1.opens the serial port using openSerialPort
* 2.gets the maximum number of memory locations alloted
* for storing the SMS messages
* 3.get all the unread messages from all the locations
* 4.sort them based on the date and time of receiving the
* message
* 5.send reply for all the SMS received */

//Connection con = null;

public void run()
{
intSmsBuf=new Vector();
try{
this.sleep(10);}
catch(Exception e)
{
}
globalBuffer=new byte[512];
// as for initial default case ate 1, the response is ate 0 OK.
// it is set to ate 0 and the response is not considered
//boolean echoFlag=false;
boolean echoFlag=true;
boolean newMsgFlag=false;
openSerialPort();
// set command echo mode OFF

//set the mode for the input text
setTextMode();

//save the text mode
saveTextMode();

//get the save response
getSaveResponse();

// set command echo mode OFF
sendEchoOff();

// receive response for echo command
//echoFlag=getEchoResponse(); reason mentioned when echo flag is declared and initialized
getEchoResponse();

// stop receiving new message indications
offNewMsgIndication();

// get response for command : offNew MsgIndication
newMsgFlag=getResForNewMsgIndication();

// these two commands are send as startup commands to
// modem and if it fails to respond to these commands
// display the dialog " to connect the modem properly
// and to restart the application
if(echoFlag==true && newMsgFlag==true) {
// get database connection


while(true){

//ReceiveMessage();
try {
con=DBOps.getConnection();
stmt=con.createStatement();
System.out.println("Database connected");

String query9 = "SELECT count(*) from new_sms_send";
int rows=0;
ResultSet rs9= stmt.executeQuery(query9);
if(rs9.next())
rows = rs9.getInt(1);
System.out.println("rows are:"+rows);

if(rows == 0)
//SendMessage();
ReceiveMessage();
else
//ReceiveMessage();
SendMessage();




}//end of try
catch(SQLException se) {
se.printStackTrace();
System.out.println(se.getMessage());
JOptionPane.showMessageDialog(null,"Database connection failed:"+se.getMessage(),"Information",JOptionPane.INFORMATION_MESSAGE);
System.exit(1);
}
}//end of while
}//end of if where port and database connection
else {
JOptionPane.showMessageDialog(null,"Cannot start the application \n as there is no response from modem","Information",JOptionPane.INFORMATION_MESSAGE);
System.exit(1);
}



}//end of run
//Method to send the message from DB
public void SendMessage() {
//if(flag ==0){
//System.out.println("send is called now");
try{
stmt=con.createStatement();
//System.out.println("Database connected");

String query9 = "SELECT count(*) from new_sms_send";
int rows=0;
ResultSet rs9= stmt.executeQuery(query9);
if(rs9.next())
rows = rs9.getInt(1);
System.out.println("rows are:"+rows);
if(rows!=0)
{
ResultSet rs1;
String query1 = "SELECT * FROM new_sms_send";
rs1 = stmt.executeQuery(query1);
//System.out.println("query executed");

while(rs1.next()){
int id = Integer.parseInt(rs1.getString(1));
String mobile = rs1.getString(2);
long mobileNum = Long.parseLong(mobile);
String sender = rs1.getString(3);
String sndMsg = rs1.getString(4);
int att = rs1.getInt(5);
System.out.println("query executed:"+id);
String time = rs1.getString(6);
/*if(rs.getString(5).equals("0"))
{
time="0/0/0000 00:00:00 AM";
}*/
System.out.println("time is:"+time);
String sndMsgs = sndMsg+"\t\t\n " +"SENDER:\n"+sender;
// boolean flag=true;
if(att==0)
{


//for(int i=0;i<rows;i++)
//{
sendReply(mobileNum,sndMsgs);
boolean status=rcvSendStatus();
if(status==true)
{
System.out.println("Send Success");

try
{

//con = DBOps.getConnection();
stmt = con.createStatement();
String query = "INSERT INTO sucessful_send (message_id, cell_number, sender, message, send_time) values ("+id+","+mobileNum+", '"+sender.trim()+"', '"+sndMsg.trim()+"','"+time+"')";
System.out.println("pasted in suces send table");
System.out.println("INSERT INTO sucessful_send (message_id, cell_number, sender, message, send_time) values ("+id+","+mobileNum+", '"+sender.trim()+"', '"+sndMsg.trim()+"','"+time+"')");
stmt.executeUpdate(query);

String query4 = "DELETE FROM new_sms_send WHERE (message_id = "+id+")";
stmt.executeQuery(query4);
System.out.println("Deleted successful");
System.out.println("DELETE FROM new_sms_send WHERE (message_id = "+id+")");

}
catch(Exception e)
{
}
}//end of if for status


else
{
try{
//con = DBOps.getConnection();
stmt = con.createStatement();
String query10 = "INSERT INTO unsusessful_send (message_id, cell_number, sender, message, send_time) values ("+id+","+mobileNum+", '"+sender.trim()+"', '"+sndMsg.trim()+"','"+time+"')";
System.out.println("pasted in unsuces send table");
System.out.println("INSERT INTO unsusessful_send (message_id, cell_number, sender, message, send_time) values ("+id+","+mobileNum+", '"+sender.trim()+"', '"+sndMsg.trim()+"','"+time+"')");
stmt.executeUpdate(query10);

String query5 = "DELETE FROM new_sms_send WHERE (message_id = "+id+")";
stmt.executeQuery(query5);
System.out.println("Deleted successful");
System.out.println("DELETE FROM new_sms_send WHERE (message_id = "+id+")");
System.out.println("upd is completed");

}
catch(Exception e){
}
}
}//end of if(att==0)
//continue;
}//end of while loop
//break;
//ReceiveMessage();
//continue;
//break;
}

}

catch(Exception e){
}//end of while(rs1)

System.out.println("sen is completed");

try{
Thread.sleep(1000);}catch(Exception e){}
}//End of the send method
//Method to receive message and store it into the DB
public void ReceiveMessage(){
//if(flag ==1){

System.out.println("Receive is called now");
sendReqForMaxLoc();
//System.out.println("max location");

// get maximum memory capacity
getResForMaxLoc();
//System.out.println("max location12");


// if(flag ==false){

//message sending part should be done then after database should be update like
// send request to get the maximum memory capacity


if(MAXLOC > 0 ) {
// timer for sending the reply
int delay=60000;
ActionListener actionListenerForReply=new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
sleep(10);
} catch(InterruptedException ie) {
}
System.out.println("value in sim is:"+MAXLOC);
// get msgs from each location ( ie for x locations)
for(int i=0;i<MAXLOC;i++) {
// send request to get the message or SMS in this case
sendReqForMsg(i+1);
// receive SMS
String rcvMsg=getResForMsg();
System.out.println("the strgb is:"+rcvMsg);
if(!rcvMsg.trim().equals("ERROR"))

{
// parse the msg
//System.out.println("parsing started");
String[] parMsg=rcvMsg.split(",");

String msg=new String();
boolean unRead=false;
boolean validMsg=false;
// if the msg is not an error msg
if(parMsg.length > 1) {
// if msg is NOT READ
if(parMsg[0].trim().equals("+CMGR: \"REC UNREAD\"")) {
//if(parMsg[0].trim().equals("+CMGR: \"REC READ\"")) {
//System.out.println("parMsg:"+parMsg[0]);
unRead=true;
}

//msgType=INVALID;
if(unRead==true) {
/* 0 1 2 3 4 5 6 7 8 9
+CMGR: "REC READ","+919866524337",,"05/08/11,19:10:32+08",145,4,0,0,"+9198450870
012345678901234
10 11
01",145,15
this 1234567890
OK */
byte crByte[]=new byte[1];
crByte[0]=13;
String cr=new String(crByte);
//System.out.println("data is:"+ crByte[0] + "new:" + cr.hashCode());
//System.out.println("parsing started2");
//System.out.println("is that:"+parMsg[1]);
//System.out.println("is that:"+parMsg[2].hashCode());
//System.out.println("is that:"+parMsg[3]);
//System.out.println("is that:"+parMsg[4]);
//System.out.println("is that:"+parMsg[5].hashCode());
//String[] msgSubStr = null;
String[] msgSubStr=parMsg[11].split(cr);
//System.out.println("data is:"+parMsg[11].split(cr).length);
// get the actual msg from the SMS received
int msgLen=Integer.parseInt(msgSubStr[0]);
System.out.println("data:"+msgSubStr);
msg=parMsg[11].substring(3,3+msgLen);
//System.out.println("parsing started3"+msgLen);
// find the msg type
//msgType=getMsgType(msg);
System.out.println("msg:"+msg);
//System.out.println("msg type:"+msgType);
}
//if(unRead==true && msgType!=INVALID) {
if(unRead==true ) {
// if it is unread, store mobile number and
// msg in the object of RequestSMS and store in internal buffer
reqSMS=new RequestSMS();
long mobileNo=Long.parseLong(parMsg[1].substring(4,14));
reqSMS.set(mobileNo,msg,parMsg[3]+" "+parMsg[4],false);
intSmsBuf.add(reqSMS);
deleteSMSFromSIM(i+1);
}
// delete SMS from SIM
//deleteSMSFromSIM(i);
} // if msg.lENGTH>1
}//end of else
else{
SendMessage();
}
}// for < MAXLOC
// sort this internal buffer based on date and time
RequestSMS reqSMSi,reqSMSj;
/*for(int i=0;i<intSmsBuf.size();i++) {
reqSMSi=(RequestSMS)intSmsBuf.get(i);
for(int j=0;j<intSmsBuf.size();j++) {
reqSMSj=(RequestSMS)intSmsBuf.get(j);
if(reqSMSi.dateTime.compareTo(reqSMSj.dateTime) > 0) {
intSmsBuf2=(Vector)intSmsBuf.clone();
intSmsBuf2.set(i,(RequestSMS)intSmsBuf.get(j));
intSmsBuf2.set(j,(RequestSMS)intSmsBuf.get(i));
intSmsBuf=(Vector)intSmsBuf2.clone();
}
}
}//end for intsmsbuf */
// remove msgs from internal buffer which are
// successfully send
/*for(int i=0;i<intSmsBuf.size();i++) {
reqSMSi=(RequestSMS)intSmsBuf.get(i);
if(reqSMSi.sentStatus==true) {
intSmsBuf.removeElementAt(i);
i=i-1;
}
}//end of removebuffer*/
}//end of action performed
};//end of actionlistener
timerTimeOut=new javax.swing.Timer(delay,actionListenerForReply);
timerTimeOut.setRepeats(true);
timerTimeOut.start();
} //end of if for MAXLOC
else {
JOptionPane.showMessageDialog(null,"SIM has no memory support","Information",JOptionPane.INFORMATION_MESSAGE);
System.exit(1);
}

//flag=true;
//}
//SendMessage();
try{Thread.sleep(1000);}catch(Exception e){}

}//end of receiving

//}//end of while


/* set the text mode */
public void setTextMode() {
try
{
String cmd="at+csdh=1";
outputStream.write(cmd.getBytes());
//write CR
outputStream.write(13);
}
catch (IOException e)
{}
}

/*save the text mode*/
public void saveTextMode() {
try
{
String cmd="at&w";
outputStream.write(cmd.getBytes());
//write CR
outputStream.write(13);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null,"");
}
}

/*get the saved response*/
public boolean getSaveResponse() {
while(ACK==0) {
}
String strGB=new String();
for(int i=0;i<index;i++) {
if(globalBuffer[i]!=10 && globalBuffer[i]!=13) {
strGB+=(char)globalBuffer[i];
//System.out.println(globalBuffer[i]);
}
}
ACK=0;

if((strGB.trim()).equalsIgnoreCase("OK")) {
return true;
} else {
return false;
}
}


/* sendEchoOff method */
public void sendEchoOff() {
try {
String cmd="ate 0";
outputStream.write(cmd.getBytes());
// write CR
outputStream.write(13);
} catch (IOException e) {}
}


/* getEchoOffResponse method */
public boolean getEchoResponse() {
while(ACK==0) {
}
String strGB=new String();
for(int i=0;i<index;i++) {
if(globalBuffer[i]!=10 && globalBuffer[i]!=13) {
strGB+=(char)globalBuffer[i];
//System.out.println(globalBuffer[i]);
}
}
ACK=0;

if((strGB.trim()).equalsIgnoreCase("OK")) {
return true;
} else {
return false;
}
}

/* stop receiving the indication of New Message */
public void offNewMsgIndication() {
try {
String cmd="at+cnmi=1,1,0,0";
outputStream.write(cmd.getBytes());
// write CR
outputStream.write(13);
} catch (IOException e) {}
}

/* get response for stopping the NewMessageIndication */
public boolean getResForNewMsgIndication() {
while(ACK==0) {
}
String strGB=new String();
for(int i=0;i<index;i++) {
if(globalBuffer[i]!=10 && globalBuffer[i]!=13) {
strGB+=(char)globalBuffer[i];
}
}
ACK=0;
if((strGB.trim()).equalsIgnoreCase("OK")) {
return true;
} else {
return false;
}
}

/* send request for maximum memory locations
that are supported by SIM */
public void sendReqForMaxLoc() {
try {
String cmd="at+cpms?";
outputStream.write(cmd.getBytes());
// write CR
outputStream.write(13);
} catch (IOException e) {}
}

/* get response for maximum memory locations
that are supported by SIM */
public void getResForMaxLoc() {
while(ACK==0) {
}
String strGB=new String();
for(int i=0;i<index;i++) {
strGB+=(char)globalBuffer[i];
}
String[] s=strGB.split(",");
MAXLOC=Integer.parseInt(s[2]);
ACK=0;
}

/** send request for message at specified
memory location */
public void sendReqForMsg(int msgIndex) {
try {
String cmd="at+cmgr="+msgIndex;
outputStream.write(cmd.getBytes());
// write CR
outputStream.write(13);
} catch (IOException e) {}
}

/** get response for the requested message */
public String getResForMsg() {
while(ACK==0) {
}
String strGB=new String();
for(int i=0;i<index;i++) {
strGB+=(char)globalBuffer[i];
}
ACK=0;
return strGB;
}

/** delete SMS from SIM */
public void deleteSMSFromSIM(int msgIndex) {
try {
String cmd="at+cmgd="+msgIndex;
outputStream.write(cmd.getBytes());
// write CR
outputStream.write(13);
} catch (IOException e) {}
}
/* public void deleteSMSFromSIM(int msgIndex) {

try {
for(int i=1;i < msgIndex;i++){
String cmd="at+cmgd="+i;

outputStream.write(cmd.getBytes());
//i++;

System.out.println("the current message index:"+i);
System.out.println("Message deleted from"+ i +" location");
// write CR
outputStream.write(13);
continue;
}
}
catch (IOException e) {}

}*/
/* send reply to the mobile number */
public void sendReply(long mobileNum,String msg) {
try {
String cmd="at+cmgs=\""+mobileNum+"\"";
outputStream.write(cmd.getBytes());
// write CR
outputStream.write(13);
//after receiving '>' , send msg and ctrl+z
while(ACK==0) {
}
//char gr=(char)globalBuffer[0];
ACK=0;
//msg="C "+msg+"?";
cmd=msg;
outputStream.write(cmd.getBytes());
outputStream.write(26);
//System.out.println(outputStream.write(26));
} catch (IOException e) {}
}

/** receive the status of the message that is send */
public boolean rcvSendStatus() {
while(ACK==0) {
}
String strGB=new String();
for(int i=0;i<index;i++) {
strGB+=(char)globalBuffer[i];
//System.out.println("buffer value:"+strGB[i]);
}
ACK=0;
// if the response is +CMGS(out of +CMGS: 23 <CR> OK) then send success
// else send failed
if(strGB.substring(2,7).equalsIgnoreCase("+CMGS")) {
return true;
} else {
return false;
}
}
/* *open serial port and set the required parameters */
public void openSerialPort() {
try {
System.out.println("Opening Comm port"+this.getName());
//portId = CommPortIdentifier.getPortIdentifier(ResourceLoader.getString("port"));
portId = CommPortIdentifier.getPortIdentifier("COM1");
System.out.println("connected to the port");
} catch(NoSuchPortException nspe) {
JOptionPane.showMessageDialog(null,"Port COM1 Not Found","Information",JOptionPane.INFORMATION_MESSAGE);
System.out.println("In NoSuchPortException "+nspe.getMessage());
//nspe.printStackTrace(10);
System.exit(1);
}
try {
serialPort = (SerialPort) portId.open("ListenPort", 2000);

} catch (PortInUseException e) {
System.out.println("Port in use.");
}
try {
outputStream = serialPort.getOutputStream();
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
//serialPort.setSerialPortParams(38400,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
Logging.addToLogFile("Port is connected.");
}
/* Close serial port */
public void closePort() {
Logging.addToLogFile("Closed the port successfully.");
serialPort.close();
System.exit(0);
}

/** serialEvent method takes the events on serial port as input
if data is available on serial port, read the data in to buffer*/

public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
System.out.println("BI");
break;

case SerialPortEvent.OE:
System.out.println("OE");
break;

case SerialPortEvent.FE:
System.out.println("FE");
break;

case SerialPortEvent.PE:
System.out.println("PE");
break;

case SerialPortEvent.CD:
System.out.println("CD");
break;

case SerialPortEvent.CTS:
System.out.println("CTS");
break;

case SerialPortEvent.DSR:
System.out.println("DSR");
break;

case SerialPortEvent.RI:
System.out.println("RI");
break;

case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
//System.out.println("OUTPUT_BUFFER_EMPTY");
break;

case SerialPortEvent.DATA_AVAILABLE:
System.out.println("DATA_AVAILABLE");
byte readBuffer[]=new byte[1024];
int numBytes=0;
try {
this.sleep(1000);
index=0;
//System.out.println("Printing No of Bytes");
while(inputStream.available()>0 ) {
numBytes=inputStream.read(readBuffer);
System.out.println("Number of Bytes:::::::"+numBytes);
for(int i=0;i<numBytes;i++) {
globalBuffer[index]=readBuffer[i];
index++;
}
}
} catch(InterruptedException ie) {
} catch(IOException ie) {
}
ACK=1;
break;
}
}
}


/* Database operations */
/** Datebase is newly created with SQL Server on Jan 15 2007 by Sasi krishna and Deepthi*/
class DBOps {
public static Connection connection=null;

/* get database connection */
public static Connection getConnection() {
try {
//String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
Class.forName(ResourceLoader.getString("driver"));
connection = DriverManager.getConnection("jdbc:sqlserver://"+ResourceLoader.getString("constring")+";databaseName=sms",ResourceLoader.getString("uname"),ResourceLoader.getString("password"));
Statement stmt = connection.createStatement();

//String url = "jdbc:sqlserver://localhost;databaseName=sms" ;
//connection = DriverManager.getConnection (url, "sa", "");
//System.out.println("database connected");
// getvalues(stmt);
}
catch(Exception e)
{
System.out.println(e);
}
//System.out.println("Returning Connection");
return connection;

}
/* close the database connection */
public static void closeDB() {
if(connection != null) {
try {
connection.close();
} catch(SQLException se) {
se.printStackTrace();
System.out.println(se.getMessage());

JOptionPane.showMessageDialog(null,"Database connection failed:"+se.getMessage(),"Information",JOptionPane.INFORMATION_MESSAGE);
System.exit(1);
}
connection=null;
}
}
}
/** The request send from user is stored in this class object */
/** The newly received msgs are inserted in to new_sms_rcvd if the msg is valid
else the msg is inserted into the rcvd_jnk table.*/
// This code is modified on jan 17 2007 by sasi krishna
class RequestSMS{
long mobileNum;
String msg;
java.util.Date dateTime;
boolean sentStatus;
Statement stmt ;
/* set the values with the information from the request SMS received */
public void set(long num, String rcvMsg,String date_Time,boolean status) {
mobileNum=num;
msg=rcvMsg;

//"05/08/11,19:10:32+08"
//0123456789012345678901
int year=Integer.parseInt("20"+date_Time.substring(1,3));
int month=Integer.parseInt(date_Time.substring(4,6));
int date=Integer.parseInt(date_Time.substring(7,9));
int hour=Integer.parseInt(date_Time.substring(10,12));
int minutes=Integer.parseInt(date_Time.substring(13,15));
int seconds=Integer.parseInt(date_Time.substring(16,18));

dateTime=new java.util.Date(year,month,date,hour,minutes,seconds);
String time = year+"/"+month+"/"+date+" "+hour+":"+minutes+":"+seconds;
System.out.println("message received");
System.out.println(" "+mobileNum+" " +msg+" "+time);

String[] nmsg = msg.trim().split("\\s");
String checktype = nmsg[0];
System.out.println("for validaton is:"+checktype);
String real="";
for(int x=1; x<nmsg.length; x++)
{
real = real+" "+nmsg[x].trim()+" ";}
//System.out.println("the original message is:"+nmsg);
sentStatus=status;
Connection con = null;
try{
System.out.println("connecting to db");
//con = DBOps.getConnection();
stmt = con.createStatement();
ResultSet rs1;
String query1 = "SELECT msg_hrd FROM msg_header GROUP BY msg_hrd HAVING(COUNT(*) = 1)";
rs1 = stmt.executeQuery(query1);
//System.out.println("resultset created");
/* StringTokenizer st= new StringTokenizer(msg,"");
String checktype = st.nextToken();
String amsg = st.nextToken();*/

System.out.println("checktype:"+checktype);
System.out.println("amsg:"+real);
int flag=0;
while(rs1.next())
{
System.out.println("ready to insert:"+checktype+" " +rs1.getString(1));

if(checktype.trim().equalsIgnoreCase(rs1.getString(1).trim()))
{
flag = 1;

}
}
if(flag ==1)
{
System.out.println("valid message");
//String type="ATT";
String query = "INSERT INTO new_sms_rcvd (cell_number, msg_header, msg_body, rcvd_time) values ("+mobileNum+", '"+checktype.trim()+"', '"+real.trim()+"','"+time+"')";
//String query = "INSERT INTO new_sms_rcvd " + "values ('"+mobileNum+"', '"+checktype.trim()+"', '"+real.trim()+"','"+time+"')";

//System.out.println(query);
stmt.executeUpdate(query);
System.out.println("rcvd updated");
//new ListenPort().deleteSMSFromSIM(10);

}

else
{
System.out.println("In valid message");
String checked = checktype.trim()+" "+real.trim()+" ";
String query3 = "INSERT INTO rcvd_junk (cell_number, msg_body, rcvd_time) values ("+mobileNum+", '"+checked.trim()+"','"+time+"')";
//String query3 = "INSERT INTO rcvd_junk " + "values ('"+mobileNum+"', '"+checked.trim()+"','"+time+"')";
//System.out.println("inserted into junk table");
stmt.executeUpdate(query3);
System.out.println("junk updated");
//new ListenPort().deleteSMSFromSIM(10);

}

}//end of while loop


catch(SQLException e)
{
}
}//emthod closing

}//end of class
/*
* StartupForm class is used to display the form which consists of the three
* operations - start application, close application and exit.
* @version 1.0
* @author Sasi Krishna and Deepthi
*/

class StartupForm extends JFrame implements ActionListener {

public JButton btnStart,btnStop,btnExit;
private JPanel[] pnl;
Connection con = null;
ListenPort close = new ListenPort();
// private AppForm appForm;
/*
* StartupForm constructor allocates memory for all the controls placed on
* this form, sets the layout for the frame, location of the
* the frame, size of the frame. button click actions are handled by action
* listener. Tilte for the form is set using the setTitle method of the
* frame. addActionListener, actionPerformed methods of ActionListener
* interface are used.
* when this constructor is being called, the start and the exit buttons
* are enabled and the stop button is disabled.
*/
public StartupForm() {
//Make sure we have nice window decorations.
//JFrame frame = new JFrame();
//frame.setUndecorated(true);
//frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);

this.setUndecorated(true);
this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);

setDefaultLookAndFeelDecorated(true);

setTitle("SMS Application");
Container container=getContentPane();
btnStart=new JButton("Start");
//btnStop=new JButton("Stop");
btnExit=new JButton("Stop");

btnStart.addActionListener(this);
//btnStop.addActionListener(this);
btnExit.addActionListener(this);

pnl=new JPanel[3];
for(int i=0;i<3;i++) {
pnl[i]=new JPanel();
pnl[i].setLayout(new FlowLayout());
}
container.setLayout(new GridLayout(3,1));
pnl[0].add(btnStart);
//pnl[1].add(btnStop);
pnl[2].add(btnExit);

container.add(pnl[0]);
container.add(pnl[1]);
container.add(pnl[2]);
setSize(200,150);
setLocation(240,180);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// btnStop.setEnabled(false);
btnExit.setEnabled(false);
show();
}
/*
* In the actionPerformed method the event is passed as input parameter
* and when the Start button is pressed the application form for starting
* the application is displayed and the object of this form is passed as
* a parameter to its constructor, by disabling this form.
* when exit button is pressed the total application gets closed.
* the stop button is enabled in the start applicatin form, if the operator
* is a valid operator
* when stop button is pressed the application form for closing the
* application is displayed, this form is disabled and if the operator is having the rights to
* close the application he can stop the application, otherwise the
* operator can close the closing the form
*/

public void actionPerformed(ActionEvent event) {

if(event.getSource()==btnStart) {
//appForm=new AppForm(this);

close.start();
this.setState(JFrame.ICONIFIED);
btnExit.setEnabled(true);
btnStart.setEnabled(false);

}

if(event.getSource()==btnExit) {
try{
DBOps.closeDB();
close.closePort();
System.exit(0);

}
catch(Exception e)
{
}
}
}
}




can u tell me how to reduce the CPU cycles bcoz on running this application other applications are opening and at the same time if i want to close this application the form which is containg stop buton is not all showing the button only the layout of the form is displaying. so i want to reduce the cpu cycles and i want to open the form immediately when i maximize the form and on clicking the stop button i want to exit from the application.[/code:1bfepuzv]

Click here to read the whole forum topic