Remote Method Invocation RMI program code using Java



The program is written 3 files namely :RMI.java , RMIserver.java, RMIclient.java. This program implements RMI concept in java .
The Java Remote Method Invocation Application Programming Interface, or Java RMI, is a Java API that performs the object-oriented equivalent of remote procedure calls , with support for direct transfer of serialized Java objects and distributed garbage collection.

CODE:


RMI.java

import java.rmi.*;

public interface RMI extends Remote
{
void receiveMessage(String x) throws RemoteException;
}




RmiServer.java

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.net.*;

public class RmiServer extends java.rmi.server.UnicastRemoteObject
implements RMI
{
    int      thisPort;
    String   thisAddress;
    Registry registry;    // rmi registry for lookup the remote objects.

    // This method is called from the remote client by the RMI.
    // This is the implementation of the “ReceiveMessageInterface”.
    public void receiveMessage(String x) throws RemoteException
    {
        System.out.println(x);
    }

    public RmiServer() throws RemoteException
    {
        try{
            // get the address of this host.
            thisAddress= (InetAddress.getLocalHost()).toString();
        }
        catch(Exception e){
            throw new RemoteException("Can't get inet address.");
        }
        thisPort=3232;  // this port(registry’s port)
        System.out.println("This address="+thisAddress+",port="+thisPort);
        try{
        // create the registry and bind the name and object.
        registry = LocateRegistry.createRegistry( thisPort );
            registry.rebind("rmiServer", this);
        }
        catch(RemoteException e){
        throw e;
        }
    }
  
    static public void main(String args[])
    {
        try{
        RmiServer s=new RmiServer();
    }
    catch (Exception e) {
           e.printStackTrace();
           System.exit(1);
    }
     }
}


RmiClient.java

import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;

public class RmiClient
{
    static public void main(String args[])
    {
       RMI rmiServer;
       Registry registry;
       String serverAddress=args[0];
       String serverPort=args[1];
       String text=args[2];
       System.out.println("Sending "+text+" to "+serverAddress+":"+serverPort);
       try{
           // get the “registry”
           registry=LocateRegistry.getRegistry(
               serverAddress,
               (new Integer(serverPort)).intValue()
           );
           // look up the remote object
           rmiServer=
              (RMI)(registry.lookup("rmiServer"));
           // call the remote method
           rmiServer.receiveMessage(text);
       }
       catch(RemoteException e){
           e.printStackTrace();
       }
       catch(NotBoundException e){
           e.printStackTrace();
       }
    }
}





OUTPUT:



Server Output:-
C:\Program Files\Java\jdk1.5.0\bin>javac RMI.java

C:\Program Files\Java\jdk1.5.0\bin>javac RmiServer.java

C:\Program Files\Java\jdk1.5.0\bin>rmic RmiServer

C:\Program Files\Java\jdk1.5.0\bin>java RmiServer
This address=i3-05/192.168.100.180,port=3232
Hi,
This
is
Ascyena


Client Output:-
C:\Program Files\Java\jdk1.5.0\bin>javac RmiClient.java

C:\Program Files\Java\jdk1.5.0\bin>java RmiClient 192.168.100.180 3232 Hi,
Sending Hi, to 192.168.100.180:3232

C:\Program Files\Java\jdk1.5.0\bin>java RmiClient 192.168.100.180 3232 This
Sending This to 192.168.100.180:3232

C:\Program Files\Java\jdk1.5.0\bin>java RmiClient 192.168.100.180 3232 is
Sending is to 192.168.100.180:3232

C:\Program Files\Java\jdk1.5.0\bin>java RmiClient 192.168.100.180 3232 Ascyena
Sending Ascyena to 192.168.100.180:3232

Read more »

Revers Name Resolution Program code using java

PROGRAM NAME: REVERSE NAME RESOLUTION

In computer networkingreverse DNS lookup or reverse DNS resolution (rDNS) is the determination of a domain name that is associated with a given IP address using the Domain Name Service (DNS) of the Internet.

COMPLIED USING : JAVA JDK or NETBEANS IDE

CODE:



ReverseNameResolution.java

import java.net.*;
import java.util.Scanner;


class ReverseNameResolution {

    public static void main(String[] args) {

        System.out.println("Enter the IP address of the pc :-");
        Scanner in=new Scanner(System.in);
        String ip=in.nextLine();
        InetAddress inetAddress = null;
        // Get the host name given textual representation of the IP address
        try
        {
           inetAddress = InetAddress.getByName(ip);
           // Determines the IP address of a host, given the host's name.
        }
        catch (UnknownHostException e)
        {
            System.out.println("Unknown Host Exception");
            e.printStackTrace();
        }

        // The InetAddress object
        System.out.println("InetAddress object " + ip.toString());
        // Converts this IP address to a String.


        //  Gets the host name for this IP address.
        System.out.println( "Host name of " + ip + " is " + inetAddress.getHostName());

        // Gets the fully qualified domain name for this IP address.
        System.out.println("Canonical host name of " + ip + " is " + inetAddress.getCanonicalHostName());

    }

}


OUTPUT:



Enter the IP address of the pc :-
192.168.100.180
InetAddress object 192.168.100.180
Host name of 192.168.100.180 is I3-05
Canonical host name of 192.168.100.180 is I3-05
Read more »

Java Program code to count vowels in given word

The program counts the number of vowels in the given word
Complied using JDK and Netbeans IDE


Code:



                                                                     
                                                                     
                                                                     
                                             
package vowels;

import java.io.*;
 public class vowels  {
        public static void main(String[] args)throws IOException {
        BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the string ");
        String s=stdin.readLine();
        int count=0;
        for(int i=0;i<s.length();i++)
        {
           char c=s.charAt(i);
          if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u'||c=='A' || c=='E' || c=='I' || c=='O' || c=='U')
           {
              count=count+1;
           }
        }
        System.out.println("vowels= "+count);
        
    }

}








Output:

                                                                     
                                                                     
                                             
 Enter the string 
 Roger
 vowels= 2


Read more »

Multiple inheritance Program Code in Java

The code Below implements the concept of multiple inheritance.The program takes Roll number of student as input using one class. Then Marks obtained in two subject .Later the marks are added together along with bonus marks and total is printed.The code is implemented using multiple inheritance concept in mind.
You can use JDK or Netbeans IDE to run below code.

                                                                     
CODE:                                                                     
                                                                     
                                             
package mulinheritance;
import java.io.*;
	class student
	{
      	int rn;
  	void getNumber(int n)
  	{
      	rn = n;
 	 }
  	void putNumber()
  	{
   	   System.out.println("Roll Number: " +rn);
  	}
	}

	class test extends student
	{
    	float pt1, pt2;
 	void getMarks(float m1, float m2)
 	{
     	pt1 = m1;
     	pt2 = m2;
	 }
 	void putMarks()
 	{
     	System.out.println("<Marks Obtained>");
     	System.out.println("sports: " +pt1);
     	System.out.println("computer: " +pt2);
 	}
	}
 	interface theory
 	{
     	float theory= 10.0F;
     	void putWt();
	 }

	class result extends test implements theory
	{
    	float total;
    	public void putWt()
   	 {
      	 System.out.println("practical score: " +theory);
    	}
    	void display()
    	{
        total = pt1+pt2+theory;
        putNumber();
        putMarks();
        putWt();
        System.out.println("Total score: " +total);
       }
	}
	public class mulinheritance {
   	 public static void main(String[] args)throws Exception {
        try
        {
        result stud1 = new result();
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the roll number: ");
        int num = Integer.parseInt(bf.readLine());
        stud1.getNumber(num);
        System.out.println("Enter the marks in sports: ");
        int ma = Integer.parseInt(bf.readLine());
        System.out.println("Enter the marks in computer: ");
        int sc = Integer.parseInt(bf.readLine());
        stud1.getMarks(ma,sc);
        stud1.display();
        }
        catch(Exception e) { }
        
    }

}


OUTPUT:                                                            
                                             
	Enter the roll number: 
	23
	Enter the marks in sports: 
	56
	Enter the marks in computer: 
	67
	Roll Number: 23
	<Marks Obtained>
	sports: 56.0
	computer: 67.0
	practical score: 10.0
	Total score: 133.0




Read more »

Code For Validating Email String Number Html Forms using javascript

Validation is very important when we deal with anything processing on web. The data must be validated before it is entered into the database. Validation could be on server side as well as client side. We are going to focus on validation using java script on the client side.With The below code you can validate Names which is a string , Age which is a number and a email which has syntax such as email@email.com.
To run this code you just need a java script enabled browser to test.
copy the code and rename the file with .html extension.

Code:(Put it into text file and rename the file with .html extension)




<html>
<head>
<title>
Register Form
</title>
<style type="text/css">
h3{color:white;font-size:20pt;font-family:comicsansms}
.inset
{
border-width: 8px; border-style: inset; border-color: black;padding:20pt 
}
.margin{margin-left:100pt;margin-right:100pt}
a:link {color:pink;
            text-decoration:none;
       }


a:hover {
            color:peach;
            text-decoration:none;
}
table{line-height:0.5cm;letter-spacing:2px}
</style>


<script type="text/javascript">
function chkname()
{
var exp=RegExp(/^[A-Za-z]+$/);
var str=document.getElementById("name").value;
if(exp.test(str)==false)
{
alert("Name is either empty or invalid");
}
}
function chkemail()
{
var exp=RegExp(/^(\w*\.?\_?)+@\w+(\.[a-z])+/);
var str=document.getElementById("email").value;
if(exp.test(str)==false)
{
alert("email is either empty or invalid");
}
}


function filldob()
{
var month=new Array();
month=["January","February","March","April","May","June","July","August","September","October","November","December"];
for(i=0;i<month.length;i++)
{
var op1=document.createElement("OPTION");
op1.text=month[i];
op1.value=i;
document.getElementById("mth").options[i]=op1;
}
var dt=new Date();
for(i=0;i<31;i++)
{
var op1=document.createElement("OPTION");
op1.text=i+1;
op1.value=i+1;
document.getElementById("date").options[i]=op1;
}

for(i=0;i<60;i++)
{
var str=dt.getFullYear()-i;
var op1=document.createElement("OPTION");
op1.text=str;
op1.value=str;
document.getElementById("yr").options[i]=op1;
}
}






function calc_age()
{
var now=new Date();

var dat=document.getElementById("date").value;
var mnth=document.getElementById("mth").value;
var yrs=document.getElementById("yr").value;
var d1=parseInt(dat);
var mth=parseInt(mnth);
var yr=parseInt(yrs);
var dt=new Date(yr,mth,d1,00,00,00,00);
var str=now.getFullYear()-dt.getFullYear();
if(str>0&&(dt.getMonth()-now.getMonth())>=0&&(dt.getDate()-now.getMonth())>=0)
document.getElementById("age").value=str-1;
else
document.getElementById("age").value=str-1;
}
function chkfeb()
{
if(document.getElementById("mth").value==1)
{
for(i=28;i<31;i++)
{
document.getElementById("date").options[i].text="";
}
}
else
{
for(i=28;i<31;i++)
{
document.getElementById("date").options[i].text=i+1;
}
}
}
function chkmth()
{
if((document.getElementById("mth").value==3)||(document.getElementById("mth").value==5)||(document.getElementById("mth").value==8)||(document.getElementById("mth").value==10))
{
for(i=30;i<31;i++)
{
document.getElementById("date").options[i].text="";
}
}

}
</script>
</head>

<body style="background-color:orange"         onload="filldob();calc_age()">
<center>
                            <h3>>>>>>Fill In The  Details to Register<<<<</h3>
</center>
<br>


<form style=padding:auto;font-size:10pt onSubmit="chkname();chkemail()">
<div class="inset margin">
<table style="color:Black">
<tr>
<td>
Name:</td><td><input type="textbox" id="name"></td>
</tr>
<tr>
<td>Address:</td>
<td><textarea name="add" id="addr"></textarea></td>
</tr>
<tr>
<td>D.O.B:</td>
<td><select id="date" onChange="calc_age()"></select>
<select id="mth" onChange="chkfeb();chkmth();calc_age()"></select>
<select id="yr" onChange="calc_age()"></select></td>
</tr>
<tr>
<td>Age:</td><td><input type="textbox" id="age"></td>
</tr>
<tr>
<td>Email ID:</td>
<td><input type="textbox" id="email"></td>
</tr>
<tr>
<td>Gender:</td>
<td><input type=radio>Male
<input type=radio>Female</td>
</tr>
<tr>
<td>Hobbies:</td>
<td><input type="checkbox" name="ch" value:"play">Playing
<input type="checkbox" name="ch" value:"dance">Dancing
<input type="checkbox" name="ch" value:"read">Reading</td>
</tr>
<tr>

<td><input type="submit" value="Submit">
<input type="submit" value="Reset"></td>

</tr>

</table>
</div>
</form>
<br>

</body>
</html>





OUTPUT:


Read more »

Palindrome Program in Java

The Program was complied using Netbeans IDE.

PROGRAM:



                                                                                                               
package palindrome;
import java.io.*;

public class palindrome {

    
     public static void main(String[] args)throws IOException {
        BufferedReader st=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the String ");
       String str=st.readLine();
        String s="";
       for(int i=(str.length())-1;i>=0;i--)
        s=s+str.charAt(i);
        if(s.equals(str))
        System.out.println(str+" is Palindrome ");
        else
        System.out.println(str+" is not a Palindrome");
       
    }

}


OUTPUT:





Enter the String
 aga
aga is Palindrome
Read more »

Java program to calculate sum of integers between given numbres


The program was complied using Netbeans IDE .

PROGRAM:


package intby7;
import java.io.*;


 public class intby7 {
 public static void main(String[] args)throws IOException {
        BufferedReader st=new BufferedReader(new InputStreamReader(System.in));
        try
        {
        System.out.println("Enter the no from");
        int no=Integer.parseInt(st.readLine());
        System.out.println("Enter the no to");
        int nn=Integer.parseInt(st.readLine());
        int sum=0;
        for(int i=no;i<nn;i++)
        {
            int rem=i%7;
            if(rem==0)
            {
                System.out.println(i);
                sum=sum+i;
            }
        }
        System.out.println("The sum of integer between "+no+" and "+nn+" is "+sum);
        }
        catch(Exception e) { }
       
    }

}





OUTPUT:



        Enter the no from
 100
 Enter the no to
 200
 105
 112
 119
 126
 133
 140
 147
 154
 161
 168
 175
 182
 189
 196
 The sum of integer between 100 and 200 is 2107


Read more »

Implementing Client Server chat Program in Java computer Networks Concept

Here is a client server program implemented in java . The program was complied using Netbeans IDE with both programs opened in different tabs and was able to make connection and send messages from client to server. The program was tested in LAN network. if you are working on some other network please make changes required in the code.

CLIENT.JAVA


package cn;
import java.io.*;
import java.net.*;

//cleint side program
public class client
{
    Socket requestSocket;
    ObjectOutputStream out;
    ObjectInputStream in;
    String msg;
    int portno;
    server(){}
    void run()
    {
        try
        {
            portno=2004;
            requestSocket=new Socket("0.0.0.0",portno);
            System.out.println("Connect to local host "+portno);
            out=new ObjectOutputStream(requestSocket.getOutputStream());
            out.flush();
            in=new ObjectInputStream(requestSocket.getInputStream());
            do
            {
                try
                {
                    msg=(String)in.readObject();
                    System.out.println("Server> "+msg);
                    BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
                    System.out.print("Enter the message: ");
                    msg=obj.readLine();
                    sendMessage(msg);
                }
                catch(ClassNotFoundException e)
                {
                    System.err.println("data received in unknown format");
                }
            }
            while(!msg.equals("bye"));
        }
        catch(UnknownHostException u)
        {
            System.err.println("You are trying to connect to an unknown host");
        }
        catch(IOException io)
        {
            io.printStackTrace();
        }
        finally
        {
            try
            {
                in.close();
                out.close();
                requestSocket.close();
            }
            catch(IOException i)
            {
                i.printStackTrace();
            }
        }
    }
    void sendMessage(String msg)
    {
        try
        {
            out.writeObject(msg);
            out.flush();
            System.out.println("Client>" +msg);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }
    public static void main(String[] args)throws IOException
    {
        cleint g=new client();
        g.run();
    }
}




SERVER.JAVA


package cn;
import java.io.*;
import java.net.*;
public class server
{
    ServerSocket providerSocket;
    Socket connection=null;
    ObjectOutputStream out;
    ObjectInputStream in;
    String msg;
    int portno;
    client(){}
    void run()
    {
        portno=2004;
        try
        {
            providerSocket=new ServerSocket(portno,10);
            System.out.println("waiting for connection");
            connection=providerSocket.accept();
            System.out.println("Connection received from "+connection.getInetAddress().getHostName());
            out=new ObjectOutputStream(connection.getOutputStream());
            out.flush();
            in=new ObjectInputStream(connection.getInputStream());
            sendMessage("Connection successfull");
            do
            {
                try
                {
                    msg=(String)in.readObject();
                    System.out.println("Cleint>" +msg);
                    BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
                    System.out.println("Enter the message:");
                    msg=obj.readLine();
                    sendMessage(msg);
                    if(msg.equals("bye"))
                        sendMessage(msg);
                }
                catch(ClassNotFoundException e)
                {
                    System.err.println("Data received in unkown format");
                }
            }
            while(!msg.equals("bye"));
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                in.close();
                out.close();
                providerSocket.close();
            }
            catch(IOException e)
            {
                e.printStackTrace();
            }
        }
    }
    void sendMessage(String msg)
    {
        try
        {
            out.writeObject(msg);
            out.flush();
            System.out.println("Server>"+msg);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }
    public static void main(String args[])
    {
        server g=new server();
        while(true)
        {
            g.run();
        }
    }
}
OUTPUT:


     SERVER:

waiting for connection Connection received from I2-03 client>Connection successfull Cleint>HI SERVER Enter the message: Server>HI CLIENT

CLIENT:

Connect to local host 2004 Server> Connection successful Enter the message: Client>HI SERVER Enter the message: Server>HI SERVER
Read more »

Java Program to convert temperature from Degree to Fahrenheit


Program complied with Netbeans IDE you can also use JDK and compile in command prompt .

PROGRAM:

package celtofar;
import java.io.*;
public class celtofar {
public static void main(String[] args) throws IOException {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the temperature in celcius: ");
double cel=Double.parseDouble(in.readLine());
double far=(cel*9)/5+32;
System.out.println("The Fahrenheit is "+far);

}
}


OUTPUT:


Enter the temperature in celcius:
40
The Fahrenheit is 104.0
Read more »

Java Program to Sort string in alphabetical order



Program complied with Netbeans IDE you can also use JDK and compile in command prompt .


PROGRAM:


package alphaorder;
import java.io.*;
import java.util.*;
public class alphaorder {
public static void main(String[] args)throws IOException {
BufferedReader st=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter the string ");
str=st.readLine();
char[] charArray = str.toCharArray();
Arrays.sort(charArray);
String nstr = new String(charArray);
System.out.println("The sorted string is "+nstr);

}
}


OUTPUT:


Enter the string
dcba
The sorted string is abcd

Read more »

Simplex Method Program in C++ Operation Research Concept


Here is the code in C++ for simplex method problem .This code is well tested for number of inputs .
You need VB 6 or TURBO C complier to run this code.

PROGRAM:


#include <stdio.h>
#include <math.h>
#define CMAX 10
#define VMAX 10
int NC, NV, NOPTIMAL,P1,P2,XERR;
double TS[CMAX][VMAX];
void Data() {
double R1,R2;
char R;
int I,J;
printf("\n SIMPLEX METHOD\n\n");
printf(" MAXIMIZE (Y/N) ? "); scanf("%c", &R);
printf("\n NUMBER OF VARIABLES OF THE FUNCTION ? ");
scanf("%d", &NV);
printf("\n NUMBER OF CONSTRAINTS ? "); scanf("%d", &NC);
if (R == 'Y' || R=='y')
R1 = 1.0;
else
R1 = -1.0;
printf("\n INPUT COEFFICIENTS OF THE FUNCTION:\n");
for (J = 1; J<=NV; J++) {
printf(" #%d ? ", J); scanf("%lf", &R2);
TS[1][J+1] = R2 * R1;
}
printf(" Right hand side ? "); scanf("%lf", &R2);
TS[1][1] = R2 * R1;
for (I = 1; I<=NC; I++) {
printf("\n CONSTRAINT #%d:\n", I);
for (J = 1; J<=NV; J++) {
printf(" #%d ? ", J); scanf("%lf", &R2);
TS[I + 1][J + 1] = -R2;
}
printf(" Right hand side ? "); scanf("%lf", &TS[I+1][1]);
}
printf("\n\n RESULTS:\n\n");
for(J=1; J<=NV; J++) TS[0][J+1] = J;
for(I=NV+1; I<=NV+NC; I++) TS[I-NV+1][0] = I;
}
void Pivot();
void Formula();
void Optimize();
void Simplex() {
e10: Pivot();
Formula();
Optimize();
if (NOPTIMAL == 1) goto e10;
}
void Pivot() {
double RAP,V,XMAX;
int I,J;
XMAX = 0.0;
for(J=2; J<=NV+1; J++) {
if (TS[1][J] > 0.0 && TS[1][J] > XMAX) {
XMAX = TS[1][J];
P2 = J;
}
}
RAP = 999999.0;
for (I=2; I<=NC+1; I++) {
if (TS[I][P2] >= 0.0) goto e10;
V = fabs(TS[I][1] / TS[I][P2]);
if (V < RAP) {
RAP = V;
P1 = I;
}
e10:;}
V = TS[0][P2]; TS[0][P2] = TS[P1][0]; TS[P1][0] = V;
}
void Formula() {;
int I,J;
for (I=1; I<=NC+1; I++) {
if (I == P1) goto e70;
for (J=1; J<=NV+1; J++) {
if (J == P2) goto e60;
TS[I][J] -= TS[P1][J] * TS[I][P2] / TS[P1][P2];
e60:;}
e70:;}
TS[P1][P2] = 1.0 / TS[P1][P2];
for (J=1; J<=NV+1; J++) {
if (J == P2) goto e100;
TS[P1][J] *= fabs(TS[P1][P2]);
e100:;}
for (I=1; I<=NC+1; I++) {
if (I == P1) goto e110;
TS[I][P2] *= TS[P1][P2];
e110:;}
}
void Optimize() {
int I,J;
for (I=2; I<=NC+1; I++)
if (TS[I][1] < 0.0) XERR = 1;
NOPTIMAL = 0;
if (XERR == 1) return;
for (J=2; J<=NV+1; J++)
if (TS[1][J] > 0.0) NOPTIMAL = 1;
}
void Results() {
int I,J;
if (XERR == 0) goto e30;
printf(" NO SOLUTION.\n"); goto e100;
e30:for (I=1; I<=NV; I++)
for (J=2; J<=NC+1; J++) {
if (TS[J][0] != 1.0*I) goto e70;
printf(" VARIABLE #%d: %f\n", I, TS[J][1]);
e70: ;}
printf("\n ECONOMIC FUNCTION: %f\n", TS[1][1]);
e100:printf("\n");
}
void main() {
Data();
Simplex();
Results();
}


OUTPUT:


MAXIMIZE (Y/N) ? y

NUMBER OF VARIABLES OF THE FUNCTION ? 2

NUMBER OF CONSTRAINTS ? 3

INPUT COEFFICIENTS OF THE FUNCTION:
       #1 ? 4
       #2 ? 10
       Right hand side ?

0

CONSTRAINT #1:
       #1 ? 2
       #2 ? 1
       Right hand side ? 50

CONSTRAINT #2:
       #1 ? 2
       #2 ? 5
       Right hand side ? 100

CONSTRAINT #3:
       #1 ? 2
       #2 ? 3
       Right hand side ? 90


RESULTS:

       VARIABLE #2: 20.000000

       ECONOMIC FUNCTION: 200.000000
 

Read more »

Image Creation Program using Java Image Processing Concept

So here is the program code written in Java Complied using netbeans or JDK 5 or 6

PROGRAM:
package pgm1;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.image.*;
/*<applet code="expt1" width=100 height=100>
</applet>*/
public class pgm1 extends Applet implements ActionListener{
Button y;
Image img1,img2,img3;
int width=200,height=20;
int size=width*height;
int x=200;
int w=20;
int z=x*w;
int p_buffer1[]=new int[size];
int p_buffer2[]=new int[z];
int p_buffer3[]=new int[size];
public void init()
{
int r=0XFF;
int g=0x00;
int b=0X00;
y=new Button("create");
add(y);
y.addActionListener(this);
for(int i=0;i<size;i++)
{
p_buffer1[i]=(255<<24)|(r<<16)|(g<<8)|b;
}
img1=createImage(new MemoryImageSource(width,height,p_buffer1,0,10));
r=0X00;
g=0X00;
b=0XFF;
for(int i=0;i<z;i=i+5)
{
p_buffer2[i]=(255<<24)|(r<<16)|(g<<8)|b;
}
img2=createImage(new MemoryImageSource(x,w,p_buffer2,0,10));
r=0X00;
g=0XFF;
b=0X00;
//for(int j=0;j<width;)
for(int i=0;i<z;i++)
{
p_buffer3[i]=(255<<24)|(r<<16)|(g<<8)|b;
}
img3=createImage(new MemoryImageSource(x,1,p_buffer3,0,10));


}
String str;
public void actionPerformed(ActionEvent a)
{
str=a.getActionCommand();
repaint();
}
public void paint(Graphics g)
{

if(str.equals("create"))
{
g.drawImage(img1,50,50,this);
g.drawImage(img2,50,100,this);
for(int j=0;j<w;j=j+5)
g.drawImage(img3,50,150+j,this);
}


}
}




OUTPUT: 





Read more »