Tuesday, January 25, 2011

Color Paletter using Sliders

To implement a color palette using a Slider. Here we use three sliders for Red, Blue and Green. Based on the slide value the Redness, Greenness and Blueness gets adjusted and thereby we can bring about all colors.

Download Source Code

Code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JScrollBar;
import java.applet.*;

public class Slide extends Applet
{
    JScrollBar scroll;
    JScrollBar scroll1;
    JScrollBar scroll2;
    JLabel lbl1;
    JLabel lbl2;
    JLabel lbl3;
    JPanel panel1;
    JPanel panel2;
    JPanel panel3;
    JPanel panel;
    int redness=0;
    int greenness=0;
    int blueness=0;
   
    Color co;
   
    public void init()
    {
        scroll= new JScrollBar(JScrollBar.HORIZONTAL);
        scroll.setMaximum(265);
        scroll.addAdjustmentListener(new MyAdjustmentListener());
        scroll1= new JScrollBar(JScrollBar.HORIZONTAL);
        scroll1.setMaximum(265);
        scroll1.addAdjustmentListener(new MyAdjustmentListener());
        scroll2= new JScrollBar(JScrollBar.HORIZONTAL);
        scroll2.setMaximum(265);
        scroll2.addAdjustmentListener(new MyAdjustmentListener());
        lbl1 = new JLabel("Red");
        lbl2 = new JLabel("Green");
        lbl3 = new JLabel("Blue");
       
        panel = new JPanel();
        panel1 = new JPanel();
        panel2 = new JPanel();
        panel3 = new JPanel();
        panel1.setLayout(new BorderLayout());
        panel2.setLayout(new BorderLayout());
        panel3.setLayout(new BorderLayout());
       
        panel1.add(lbl1,BorderLayout.WEST);
        panel1.add(scroll);
       
        panel2.add(lbl2,BorderLayout.WEST);
        panel2.add(scroll1);
       
        panel3.add(lbl3,BorderLayout.WEST);
        panel3.add(scroll2);
       
        panel.setLayout(new BorderLayout());
        panel.add(panel1,BorderLayout.NORTH);
        panel.add(panel2,BorderLayout.CENTER);
        panel.add(panel3,BorderLayout.SOUTH);
        add(panel,BorderLayout.NORTH);
        setSize(300,300);
        setVisible(true);
    }
   
    class MyAdjustmentListener implements AdjustmentListener
    {
        public void adjustmentValueChanged(AdjustmentEvent e)
        {
            if(e.getSource()==scroll)
                redness = e.getValue();
            else if(e.getSource() == scroll1)
                greenness = e.getValue();
            else
                blueness = e.getValue();
            co=new Color(redness,greenness,blueness);
            setBackground(co);
            repaint();
        }
    }
}   
       
Screenshots







Color Palette using matrix of buttons in Applet

Let us create an applet that contains a matrix of buttons and when clicked the background will change accordingly.


Download the Source Code

Code for Applet

import java.io.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.*;


public class matrixcolors extends Applet implements ActionListener
{
    Checkbox cf,cb;
    TextArea a;
    private Color color[]={Color.red,Color.blue,Color.cyan,Color.white,Color.black,Color.green,Color.gray,Color.lightGray,Color.darkGray,Color.yellow, Color.pink, Color.magenta,Color.orange};
    Button b[];
    Panel p1;
   
    public void init()
    {
        setLayout(new BorderLayout());
        p1=new Panel();
        b=new Button[13];
        for(int i=0;i
        {
            b[i]=new Button("");
            b[i].addActionListener(this);
            b[i].setBackground(color[i]);
            p1.add(b[i]);
        }
       
        cb=new Checkbox("Back Ground Color",true);
        cf=new Checkbox("Fore Ground Color",true);
        p1.add(cb);
        p1.add(cf);
        p1.setVisible(true);
        add(p1,BorderLayout.SOUTH);
        a=new TextArea("");
        add(a,BorderLayout.CENTER);
    }
    public void actionPerformed(ActionEvent e)
    {
        if(cb.getState())
        {
            for(int i=0;i
            {
                if(e.getSource() == b[i])
                    a.setBackground(color[i]);
            }
        }
        if(cf.getState())
        {
            for(int i=0;i
            {
                if(e.getSource()==b[i])
                    a.setForeground(color[i]);
            }
        }
    }
}

Screenshots


Wednesday, January 12, 2011

Validating Web Form Controls using DHTML

Question - Client Side Scripts for Validating Web Form Controls using DHTML.

Dynamic HTML, or DHTML, is an umbrella term for a collection of technologies used together to create interactive and animated web sites by using a combination of a static markup language (such as HTML), a client-side scripting language (such as JavaScript), a presentation definition language (such as CSS), and the Document Object Model.

I am going to create a simple HTML form where we validate the email Id..

First create the form, then using JavaScript we will validate the Email Id field, that is we will check if the user has entered a valid email id. Like if they leave @ or . we need to display to the user the error and make user they enter the proper format.

Here goes the code for the form,


<head>

<script type="text/javascript">

function validate_email(field)

{

with (field)

  {

  apos=value.indexOf("@");

  dotpos=value.lastIndexOf(".");

  len=value.length;

  if (apos<1||dotpos-apos<2||(len-dotpos)<2)

    {   document.getElementById('email_text').style.display = 'block';

    return false;}

  else

  {

  return true;}

  }

}

function validate_form(thisform)

{

with(thisform)

{

  if (validate_email(email)==false)

    {email.focus();return false;}

   alert("Registration Successful..Thank you!");   

}

}

</script>

</head>

Now we write the Javascript code to validate the email Id field,



<head>

<script type="text/javascript">

function validate_email(field)

{

with (field)

  {

  apos=value.indexOf("@");

  dotpos=value.lastIndexOf(".");

  len=value.length;

  if (apos<1||dotpos-apos<2||(len-dotpos)<2)

    {   document.getElementById('email_text').style.display = 'block';

    return false;}

  else

  {

  return true;}

  }

}

function validate_form(thisform)

{

with(thisform)

{

  if (validate_email(email)==false)

    {email.focus();return false;}

   alert("Registration Successful..Thank you!");   

}

}

</script>

</head>




Download the Source Code



Basically the script does the following,

The function above checks if the content has the general syntax of an email.
This means that the input data must contain at least an @ sign and a dot (.). Also, the @ must not be the first character of the email address, and the last dot must at least be one character after the @ sign. The by using "len-dotpos" we make sure that there are characters after those dot

So now we have created Client Side Scripts for Validating Web Form Controls using DHTML.

Saturday, January 1, 2011

Happy New Year

I Wish you all a Super New Year..Hope 2011 Bring all that you desire...:)

Wednesday, December 22, 2010

Passport Automation System

Problem statement and SRS(Software Requirements Specification) for Passport Automation System in OOAD Lab, Anna University.

(All of the information given below are just an example created for OOAD Lab exercise and not for any other purpose. And It is just a sample, with which you can build upon.)

Download the SRS for Passport Automation System


Problem Statement


Passport Automation System is used in the effective dispatch of passport to all of the applicants. This system adopts a comprehensive approach to minimize the manual work and schedule resources, time in a cogent manner. The core of the system is to get the online registration form (with details such as name, address etc.,)  filled by the applicant whose testament is verified for its genuineness by the Passport Automation System with respect to the already existing information in the database. This forms the first and foremost step in the processing of passport application. After the first round of verification done by the system, the information is in turn forwarded to the regional administrator's (Ministry of External Affairs) office. The application is then processed manually based on the report given by the system, and any forfeiting identified can make the applicant liable to penalty as per the law. The system also provides the applicant the list of available dates for appointment to 'document verification' in the administrator's office, from which they can select one. The system forwards the necessary details to the police for its separate verification whose report is then presented to the administrator. The administrator will be provided with an option to display the current status of application to the applicant, which they can view in their online interface. After all the necessary criteria has been met, the original information is added to the database and the passport is sent to the applicant. 

Software Requirements Specification

1.0 Introduction
    Passport Automation System is an interface between the Applicant and the Authority responsible for the Issue of Passport. It aims at improving the efficiency in the Issue of Passport and reduce the complexities involved in it to the maximum possible extent.
   
    1.1 Purpose

            If the entire process of 'Issue of Passport' is done in a manual manner then it would take several months for the passport to reach the applicant. Considering the fact that the number of applicants for passport is increasing every year, an Automated System becomes essential to meet the demand. So this system uses several programming and database techniques to elucidate the work involved in this process. As this is a matter of National Security, the system has been carefully verified and validated in order to satisfy it. 

    1.2 Scope

• The System provides an online interface to the user where they can fill in their personal details and submit the necessary documents (may be by scanning).
• The authority concerned with the issue of passport can use this system to reduce his workload and process the application in a speedy manner.
• Provide a communication platform between the applicant and the administrator.
• Transfer of data between the Passport Issuing Authority and the Local Police for verification of applicant's information.
• Users/Applicants will come to know their status of application and the date in which they must subject themselves for manual document verification.

    1.3 Definitions, Acronyms and the Abbreviations       

• Administrator - Refers to the super user who is the Central Authority who has been vested with the privilege to manage the entire system. It can be any higher official in the Regional Passport Office of Ministry of External Affairs.            
• Applicant - One who wishes to obtain the Passport.
• PAS - Refers to this Passport Automation System.
• HTML - Markup Language used for creating web pages.
• J2EE – Java 2 Enterprise Edition is a programming platform and it is the partof the java platform for developing and running distributed java applications.
• HTTP - Hyper Text Transfer Protocol.
• TCP/IP – Transmission Control Protocol/Internet Protocol is the communication protocol used to connect hosts on the Internet.

    1.4 References

            IEEE Software Requirement Specification format.

    1.5 Technologies to be used

• HTML
• JSP
• Javascript
• Java
• XML
• AJAX

    1.6 Tools to be Used   

• Eclipse IDE ( Integrated Development Enivronment)
• Rational Rose tool ( for developing UML Patterns)

    1.7 Overview   

            SRS includes two sections overall description and specific requirements - Overall description will describe major role of the system components and inter-connections. Specific requirements will describe roles & functions of the actors.
               

2.0 Overall Description

    2.1 Product Perspective

            The PAS acts as an interface between the 'applicant' and the 'administrator'. This system tries to make the interface as simple as possible and at the same time not risking the security of data stored in.This minimizes the time duration in which the user receives the passport. 

    2.2 Software Interface


• Front End Client - The applicant and Administrator online interface is built using JSP and HTML. The Administrators's local interface is built using Java.
• Web Server - Glassfish application server(Oracle Corporation).
• Back End - Oracle database.

    2.3 Hardware Interface

            The server is directly connected to the client systems. The client systems have access to the database in the server.

    2.4 System Functions

• Secure Registration of information by the Applicants.
• Schedule the applicants an appointment for manual verification of original documents.
• Panel for Passport Application Status Display by the Administrator.       
• SMS and Mail updates to the applicants by the administrator.
• Administrator can generate reports from the information and is the only authorized personnel to add the eligible application information to the database.

    2.5 User Characteristics   

• Applicant - They are the people who desires to obtain the passport and submit the information to the database.
• Administrator - He has the certain privileges to add the passport status and to approve the issue of passport. He may contain a group of persons under him to verify            
the documents and give suggestion whether or not to approve the dispatch of passport.
• Police - He is the person who upon receiving intimation from the PAS, perform a personal verification of the applicant and see if he has any criminal case against him before or at present. He has been vetoed with the power to decline an application by suggesting it to the Administrator if he finds any discrepancy with the applicant. He communicates via this PAS.

    2.6  Constraints        

• The applicants require a computer to submit their information.
• Although the security is given high importance, there is always a chance of intrusion in the web world which requires constant monitoring.
• The user has to be careful while submitting the information. Much care is required.

    2.7 Use Case Model Description       

   


    2.8  Assumptions and Dependencies


• The Applicants and Administrator must have basic knowledge of computers and English Language.
• The applicants may be required to scan the documents and send.