Simple UDP Time Server using Java

Today i am going to tell you how to develop simple time sever using java.net  class with UDP.

This is a simple UDP server and client programs.  The server runs on a local computer, waiting for a datagram request from a remote computer asking for the server’s current time. The server then returns its current time to the client, which in turn displays it.

Screenshot at 2013-01-21 15:31:20

Server Program >>>>> Server.java


import java.net.*;
import java.io.*;
import java.util.*;

public class Server {

public static void main(String[] args) throws Exception{

DatagramSocket ss=new DatagramSocket(1234);

while(true){

System.out.println("Server is up....");

byte[] rd=new byte[100];
byte[] sd=new byte[100];

DatagramPacket rp=new DatagramPacket(rd,rd.length);

ss.receive(rp);

InetAddress ip= rp.getAddress();

int port=rp.getPort();

Date d=new Date();   // getting system time

String time= d + "";  // converting it to String

sd=time.getBytes();   // converting that String to byte

DatagramPacket sp=new DatagramPacket(sd,sd.length,ip,port);

ss.send(sp);

rp=null;

System.out.println("Done !! ");

}

}

}

Client program >>>>>>>>> Clientnew.java


import java.net.*;
import java.io.*;

public class Clientnew {

public static void main(String[] args) throws Exception{

	System.out.println("Server Time >>>>");

	DatagramSocket cs=new DatagramSocket();

	InetAddress ip=InetAddress.getByName("localhost");

	byte[] rd=new byte[100];
	byte[] sd=new byte[100];

	DatagramPacket sp=new DatagramPacket(sd,sd.length,ip,1234);

	DatagramPacket rp=new DatagramPacket(rd,rd.length);

	cs.send(sp);

	cs.receive(rp);

	String time=new String(rp.getData());

	System.out.println(time);

	cs.close();

}

}

All About EIMS – Educational Institute Management System

I have been working on a project called “EIMS” since last 2 months with my two NIBM colleagues  ( Ravindu Kaluarchchi and Isuru Madushanka). We developed the software for a Software Competition which is conducted by a UCD Alumni Association of Srilanka.

Actually we just wanted to introduced something new thing to the world.So we hardly work on the project during the last two months.

Today I’m glad to say our product won the first award of the Software Competition.There are 40 competitors   After the winning most of the people asked from us what is  “EIMS” ? , And how its different from other solutions ? etc…..

So i created this post for answer the all the questions and Introduced our product to world.

Decision Support Center of EIMS

Decision Support Center of EIMS

What is EIMS ?

EIMS stands for Educational Institute Management System. It is a powerful management information system to easily manage any educational institute.

Actually its not like common management system we target our product for a institutes ,Universities , Schools and Colleges.

But Why EIMS ? and How is it different from other institute management systems ?

EIMS doesn’t use the traditional ways of other management systems . It uses a new approach.
More concentrated toward the lecturers.

But still allows the management to use the traditional ways of a management system.

EIMS is keep track on following areas >>>> >>>>>>>>>>>>>

1. Student Management
2. Exam Management
3. Decision Support and Reporting
4. File Sharing
5. Messaging
6. Hall management
7. Lecture Scheduling
8. Exam Scheduling

What are the Features of EIMS ? 

  • Designed for surface computers.
  • Touch Friendly interfaces.Multi User support.
  • Runs on different platforms.
  • Portable.
  • Easily maintainable.
  • Allows users to easily test the system without installing it ,by running the system from a live CD or a USB.

What are the Benefits ?

  • Lecturers can upload all their files,mark sheets,papers etc. to the server there by saves time and space.
  • Lecturers can access their lecture material from anywhere ,there by saves lecturers from the trouble of caring their lecture material , mal-functioning cd roms ,usb drives.
  • Provides easy messaging between lecturers.
  • Analyzes student , batch progress and displays in a graphical manner so that lecturers and the management can easily make their decisions.
  • Lecturers can easily view their schedules.
  • Easy scheduling system and Hall management

Technology used and the architecture of EIMS

Language         : java
Target platform : desktop ,surface

Technologies used :

  • Java RMI
  • Java persistence
  • Jasper reporting

Database            : mysql

Here is the screen shots of the Overall System >>>>>>>>>>>>>>>>>

Main Screen with the menu on the top

Main Screen with the menu on the top

You can see there is no traditional menu like file , edit ,view ect you have all the desktop to do your own works.

Main Menu

Main Menu

Simple icon style menu easy to use and user friendly.

snapshot2Simple messaging center easy to use and fast.

Lectuer's Desk for easy file sharing

Lecture’s Desk for easy file sharing

This is where lectures can upload their files lecture notes etc….

snapshot5

snapshot6

Easy reporting with EIMS decision support center

We provide an easy tool for your Reporting jobs.

snapshot7

Student search tool of our Student Management System

Our student management system consists of easy tools like this.

snapshot8

Lecture Scheduling with easy interface

We allow user to do scheduling very easily.

snapshot9

Add Shedules its fast and easy

Add Schedules its fast and easy

Screenshot at 2012-12-25 14:19:38

Exam Management with EIMS

This is the place you can manage students exam marks and generate Result sheet very easily.

Screenshot at 2012-12-25 14:20:19

Course Management

 

Student Registration Wizard

Student Registration Wizard

 

Exam Management Center

Exam Management Center

We mange to track exam scheduling also with our Exam Management Center

Screenshot at 2012-12-25 21:32:13

 

Hall Management With EIMS

Hall Management With EIMS

 

Hall Sheduling

Hall Scheduling

Most important part of the Institute is  “Hall Management “.  Solution is our Hall Booking Center

Briefly i have mention above  the overall system features that we have developed for the competition but we are flexible enough for customize and add more features of this product as you wish if you are interest with our product.

Finally I would like to thank all who helped us to success this project.

Fun terminal commands in Linux – part 1

Today i ‘m going to tell you some fun things which we can do using terminal of Linux.
When we talking about Linux its very easy to use and very flexible to use.

Linux is not an advance OS the thing is you have to be genius enough to understand the simplicity.
I will tell you how to write your own shell script to do things very easyly in my future posts.

There are lot of command in linux but here i’m going to tell you about some fun commands in Linux.
This is the first part of my Linux fun commands series.

1. Play Tom and Jerry With Linux

Your mouse pointer become a Jerry so Tom is going to catch it.
Just move your mouse pointer around screen Tom is seeking for you.

Screenshot at 2012-12-07 22:09:58
How to do it >>>>>>>>>>

1) go to terminal and type

               ” sudo apt-get install oneko “

2) after that  type

               ” oneko “

3) Press Ctrl + C to exit

************************************************************************************************************************************

2. Matrix on your terminal

Your can view Matrix of The Matrix movie on your terminal using this method.

Screenshot at 2012-12-07 22:12:53

How to do it >>>>>>>>>>

1) go to terminal and type

            ” sudo apt-get install cmatrix “

2) after that  type

    ” cmatrix “

3) Press Ctrl + C to exit

************************************************************************************************************************************

3. How to draw CowSay “Hello”

Screenshot at 2012-12-07 23:23:49

You may have seen this type of drawings from websites just like Facebook. This is the way to do it.
In here you can add your own text as a message.

How to do it >>>>>>>>>>

1) go to terminal and type

 ” sudo apt-get install cowsay “

2) after that  type

” cowsay your_Own_text “

Note : if you want to change the drawing just type

   ” cowsay -l “

it will show you avalible drawings in the file. just say if you have choose kitty.
If you want use it just type.

” cowsay -f kitty your_Own_text “

Screenshot at 2012-12-07 22:23:33

Water Bill Calculator – Android Application

While I’m new to android I look for new idea to build android application . One of my friend has developed a desktop application for Calculate monthly water bill according to the Sri Lanka  Water Board’s rules and regulations.

So I decide to developed Android version of that desktop application because android is portable than desktop application.

This is my first complete android application.

Home screen of the application with menu

this is the screen where you have to put no of units and get the result

About Me screen

 

In this application you have to put no of units that you have used within the month .

then you have to press Go button to get the the monthly charge including VAT and Service charge

.(2nd screen)

You can Download this application here………..

Its work with Android 2.1 and above.

Welcome Android : My First Android App

Hi friends today i am going to show you how to deal with android using java.

First you have to do these steps…………

1.Download the Android SDK.(Download)
2.Install the ADT plugin for Eclipse (if you’ll use the Eclipse IDE).
3.Download the latest SDK tools and platforms using the SDK Manager.

Here i’m using Eclipse IDE.

As a first step here I’hv created simple application.

This is my Virtual android device

In here when user add text to text field and………..

Adding Text

then press “Click” button it will show like this…………

Output

Here i design interface using XML file res/layout/main.xml (path of XML file)
Here is the code…..

main.xml >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.00"
        android:text="@string/hello" />

    <EditText
        android:id="@+id/edit_message"
        android:layout_width="279dp"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClick"
        android:text="@string/button_send" />

</LinearLayout>

In this code EditText means the the text field ,
TextView means the text lable and I hv use Linear Layout to place component in the screen.

When user click button the text in the the text field should be change there for i have wrote method called “onClick”
in my Main java file.
You can find your main java file in src/yourname.java.

Name of my java file is TestActivity,java

TestActivity.java >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


package test.madushanka;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class TestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) { //this is the metohd to constructing interface
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void onClick(View view){			// onClick method

    	EditText e=(EditText) findViewById(R.id.edit_message); // access text field using id of my main.xml
    	String s=e.getText().toString(); //getting the text in the text field as a String
    	e.setText("Welcome "+s+"!!!"); //set text of text field

    }
}

you can download this apk file here (Download)
Android is easy to learn if you know java well.
Try it your self just like me.

How to add Background image to a JFrame

Hi i’m today with my second post.
When talking about java swing package JFrame is the most important class for creating GUI but JFrame class does not have direct method to add image to its background.

We can add Images using JLable but the case is JLable is not the container therefor we cannot add any other  component to top of the JLable.

But i have found the method to add Background images to a JFrame and add other components top of the image.
Just like this.

Here is the JFrame

Here is the sample code….


import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;

/**
*
* @author madushanka
*/

//Creating extended class of JComponent class

class backImage extends JComponent {

Image i;

//Creating Constructer
public backImage(Image i) {
this.i = i;

}

//Overriding the paintComponent method
@Override
public void paintComponent(Graphics g) {

g.drawImage(i, 0, 0, null);  // Drawing image using drawImage method

}
}

//Creating JFrame
public class MyFrame extends JFrame {

public MyFrame() throws IOException {


// i have set size of JFrame to size of my image there for image will cover all the area of JFrame

this.setSize(500, 333);

this.setTitle("JFrame with Background image");

// read image file in my HardDisk using imageIO and assign it to buffered image reference

BufferedImage bf = ImageIO.read(new File("/home/madushanka/Desktop/myimage.jpg"));

// adding created component to the JFrame using my backImage class


this.setContentPane(new backImage(bf));

//adding other component

JButton b = new JButton("Click");
JTextField tf=new JTextField();


b.setBounds(318, 143, 98, 27);
tf.setBounds(235, 104, 180, 27);

this.add(b);
this.add(tf);
}

public static void main(String[] args) throws IOException {

MyFrame f = new MyFrame();

f.setVisible(true);
}

}

You can use this code inside the NetBeans also……………

Capture the Screen Using Java !!!!

Today i m going to tell you how to capture screen shots using java Robot class.

There are lot of automated things can do using this class such as Control mouse , Keyboard etc…..

This sample code shows you how to capture the screen and save it as a png image………………

package robottest;

import java.awt.Rectangle;

import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

/**
*
* @author Madushanka
*/
public class RobotTest {

public static void main(String[] args) throws Exception{

Robot r=new Robot();

Rectangle rectangle=new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());

BufferedImage bf=r.createScreenCapture(rectangle);

File file = new File( "screenshot.gif" );

ImageIO.write( bf, "png", file );

}

}