Tuesday, September 1, 2015

ADDING JAVA APPLICATION IN SYSTEM TRAY


import java.awt.AWTException;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public void notify1(String stat) throws AWTException
{
   
   String icoPath = "D://world.png";

        if (SystemTray.isSupported()) {
            final SystemTray systemTray = SystemTray.getSystemTray();
            final TrayIcon trayIcon = new TrayIcon(new ImageIcon(icoPath, "omt").getImage(), "Aware");
            trayIcon.setImageAutoSize(true);// Autosize icon base on space
             

            MouseAdapter mouseAdapter = new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    showframe();
                 
                }
            };
            //ADDING APP TO SYSTEM TRAY AT SPECIFIC CONDITION
            if(stat.equals("AWARE STARTED"))
            {
             trayIcon.addMouseListener(mouseAdapter);
              systemTray.add(trayIcon);
            }
       
            try
            {
               
              //DISPLAYING MESSAGE IN SYAYTEM TRAY..
                trayIcon.displayMessage("STATUS",stat,TrayIcon.MessageType.INFO);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
           
        }
       
}

RMI-REMOTE METHOD INVOCATION: IN JAVA

RMI SERVER:-

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.Scanner;

public class RmiServe
{
    public static void main(String args[])
    {
        try
        {
            RmiImpl stub=new RmiImpl();
             Registry reg=LocateRegistry.createRegistry(1099);
            reg.rebind("server", stub);
            System.out.println("SERVER STARTED...");
            while(true)
            {
                Scanner in=new Scanner(System.in);
               
                String msg=in.nextLine().trim();
                if(stub.getClient()!=null)
                {
                    RmiInterc cli=stub.getClient();
                    cli.send(msg);
                   
                }
               
               
            }
           
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
}
}
RMI CLIENT:-

import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;

public class RmiClients
{
   public static void main(String args[]) throws RemoteException, NotBoundException
   {
     RmiImpl rm=new RmiImpl();
     Registry reg=LocateRegistry.getRegistry("127.0.0.1",1099);
       RmiInterc rmi=(RmiInterc)reg.lookup("server");
        System.out.println("CONNECTED TO SERVER");
        rmi.setClient(rm);
        while(true)
            {
                Scanner in=new Scanner(System.in);
            System.out.println("ENTER VALUE");
            String msg=in.nextLine().trim();
            rmi.send(msg);
            }
      
   }
}
RMI INTERFACE:

public interface RmiInterc extends Remote
{
 public void send(String msg) throws RemoteException;
  public void setClient(RmiInterc c)throws RemoteException;
  public RmiInterc getClient() throws RemoteException;

}
RMI IMPLEMENTING CLASS:

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class RmiImpl extends UnicastRemoteObject implements RmiInterc
{
         String dat;
    public RmiInterc client=null;
     RmiImpl() throws RemoteException
    {
        super();
    }
   
    public void send(String s) throws RemoteException
        {
                                System.out.println(s);
               
        }
      public void setClient(RmiInterc c)throws RemoteException
    {
        client=c;
       
    }
                public RmiInterc getClient() throws RemoteException
        {
            return client;
        }
   

}

RECEIVING MAIL IN JAVA

import java.util.Properties;
import javax.mail.Address;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import java.util.*;
import javax.mail.*;


public class ReceiveMailing {

 
    public static void main(String[] args) throws MessagingException
    {
        Properties props = new Properties();
        props.setProperty("mail.store.protocol", "imaps");
        try {
            Session session = Session.getInstance(props, null);
            Store store = session.getStore();
            store.connect("imap.gmail.com", "complaintszero@gmail.com", "your password");
            Folder inbox = store.getFolder("INBOX");
            inbox.open(Folder.READ_ONLY);
            Message msg = inbox.getMessage(inbox.getMessageCount());
            Address[] in = msg.getFrom();
            for (Address address : in) {
                System.out.println("FROM:" + address.toString());
            }
            Multipart mp = (Multipart) msg.getContent();
            BodyPart bp = mp.getBodyPart(0);
            System.out.println("SENT DATE:" + msg.getSentDate());
            System.out.println("SUBJECT:" + msg.getSubject());
            System.out.println("CONTENT:" + bp.getContent());
        } catch (Exception mex) {
            mex.printStackTrace();
        }

    }
   
}
NOTE: FOR BOTH MAIL SEND AND RECEIVE NEED JAR FILES MAIL.JAR AND  ACTIVATION.JAR

SENDING MAIL IN JAVA

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.*
public void sendmail(String sndmail,String name,String pwd)
    {
        //change accordingly

  //Get the session object
  Properties props = new Properties();
  props.put("mail.smtp.host", "smtp.gmail.com");
  props.put("mail.smtp.socketFactory.port", "465");

  props.put("mail.smtp.starttls.enable", "true");
 props.put("mail.smtp.auth", "true");
  props.put("mail.smtp.port", "587");
 
   Session session = Session.getDefaultInstance(props,
   new javax.mail.Authenticator() {

   protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
   return new javax.mail.PasswordAuthentication("ragava08@gmail.com","YOUR PASSWORD");//change accordingly
 
   }
  });
 
  //compose message
  try
  {
   MimeMessage message = new MimeMessage(session);
   message.setFrom(new InternetAddress("ragava08@gmail.com"));//change accordingly
   message.addRecipient(Message.RecipientType.TO,new InternetAddress(sndmail.trim()));
   message.setSubject("sending maill java");
   message.setText("TEST MAIL THROUGH JAVA");
   
   //send message
   Transport.send(message);
  JOptionPane.showMessageDialog(rootPane, "MAIL SENT SUCCESSFULLY");

   //System.out.println("message sent successfully");
 
  }
  catch (MessagingException e)
  {
      throw new RuntimeException(e);
  }

    }


NOTE:
IF ABOVE CODE THROWS EXCEPTION..
CHANGE THE SESSION INSTANCE(BOLD WORDS) ... To BELOW CODE

Session s = Session.getInstance(props,new javax.mail.Authenticator()

Saturday, April 25, 2015

ANDROID WITH PHP CONNECTION

PHP CODINGS:-

<?php 

$query=mysql_connect("localhost","root","");
mysql_select_db("androidcalldb",$query);
extract($_GET);

if(isset($s1))
{
echo "GANESH";

$que=mysql_query("select max(id) as maxid from datainsert") or die("ERROR IN ID CONNECTION");
$res=mysql_fetch_array($que);
$id=$res['maxid']+1;


$query1=mysql_query("insert into datainsert(id,fname,sname)values('$id','$fname','$sname')") or die("Error in connection");
if($query1)
{
echo "succesfully submitted";

}
else
{
 echo "not submitted";

 }

}




?>


------------------------------------------------------------------------------------------------------------------------
PHP URL:
http://localhost/androidcall.php?fname=Ragaven&sname=Ganesan&s1=Submit
------------------------------------------------------------------------------------------------------------------------
ANDROID CODING:

package php.call;

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.DataInputStream;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void sub1(View v)
{
try
{

EditText e1=(EditText)findViewById(R.id.editText1);
EditText e2=(EditText)findViewById(R.id.editText2);
String fname=e1.getText().toString();
String sname=e2.getText().toString();

String ur="http://14.96.39.125/androidcall.php?fname="+fname.trim()+"&sname="+sname.trim()+"&s1=Submit";
ur=ur.replace("+", "%2B");
Log.i("Register",ur);
URL url=new URL(ur);
HttpURLConnection uc= (HttpURLConnection)url.openConnection();
DataInputStream dis= new DataInputStream(uc.getInputStream());
String t = "";String txt="";
while((t=dis.readLine()) !=null)
{
txt += t;
}
Log.i("LoginResult",txt);
Toast.makeText(getApplicationContext(), txt, Toast.LENGTH_LONG).show();
dis.close();



  }

catch(Exception e)
{
Log.i("Store ",e.getMessage());

}




}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
--------------------------------------------------------------------------------------------------------------------------
ANDROID FRONT END

PHP WAMP SERVER BACK END


Wednesday, December 24, 2014

SIMPLE DATABASE CONNECTIVITY PROGRAM IN PHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP DATABSAE</title>
</head>

<body>
<?php

$query=mysql_connect("localhost","root","");
mysql_select_db("cloud",$query) ;
$name1=$_POST['firstname'];
$name2=$_POST['lastname'];
//echo "insert into register(firstname,secondname)values('$name','$name2')";
$query1=mysql_query("INSERT into register(firstname,secondname)values('$name1','$name2')");
if($query1)
{
 echo "succesfully submitted";
 }
 else
 {
 echo "please submit again";
 }

?>
</body>
</html>

Wednesday, December 17, 2014

TIMER APPLICATION code for 20 Minutes Alert using c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Timer
{
    public partial class Form1 : Form
    {

        int i = Convert.ToInt32(0);
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            label1.Text = DateTime.Now.ToString();
           

        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            i++;
            if (i==20)
            {
                MessageBox.Show("20 minutes is left");
                i = 0;
            }

        }