Saturday, July 18, 2009

Code for Registeration

import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.FileDialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import com.sun.org.apache.xpath.internal.WhitespaceStrippingElementMatcher;


public class register extends JFrame implements ActionListener, MouseListener{
JLabel imagelab,regist, date1, photo, title, oof,nation, dob, sex,cadd, ccity,cstate, ccountry, cpincode, padd, pcity,pstate, pcountry, ppincode, mobileno, phone, email, martial, idmark1, idmark2, blood, reffer, allergy, insholder, inscompany, policy, person, relation, sign;
JTextField tregist, tdate1, toof,tnation, tdob, tccity,tcstate, tccountry, tcpincode, tpcity,tpstate, tpcountry, tppincode, tmobileno, tphone, temail, tblood, treffer, tallergy, tinsholder, tinscompany, tpolicy, tperson, trelation, tsign;
JLabel tphoto;
JComboBox ctitle,csex, cmartial;
JTextField tcadd, tpadd, tidmark1, tidmark2;
JButton browse,register, reset, cancel, print, search;
String sBrowseImage=null;
public register(){
JFrame f = new JFrame();
Container c = this.getContentPane();
regist= new JLabel("Registration No:");
this.add(regist);
regist.setBounds(10,20,150,20);

date1= new JLabel("Date:");
this.add(date1);
date1.setBounds(10,50,150,20);

photo= new JLabel("Photo:");
this.add(photo);
photo.setBounds(500,50,100,20);

imagelab= new JLabel();
this.add(imagelab);
imagelab.getBorder();
imagelab.setBounds(170,0,50,50);

title= new JLabel("Title:");
this.add(title);
title.setBounds(10,80,150,20);

oof= new JLabel("S/D/W/H of:");
this.add(oof);
oof.setBounds(10,110,150,20);

dob= new JLabel("DOB:(dd/mm/yyyy)");
this.add(dob);
dob.setBounds(10,140,150,20);

sex= new JLabel("Sex:");
this.add(sex);
sex.setBounds(500,140,150,20);

cadd= new JLabel("Contact Address:");
this.add(cadd);
cadd.setBounds(10,170,150,20);

ccity= new JLabel("City:");
this.add(ccity);
ccity.setBounds(10,200,150,20);

cstate= new JLabel("State:");
this.add(cstate);
cstate.setBounds(500,200,150,20);

ccountry= new JLabel("Country:");
this.add(ccountry);
ccountry.setBounds(10,230,150,20);

cpincode= new JLabel("Pincode:");
this.add(cpincode);
cpincode.setBounds(500,230,150,20);

padd= new JLabel("Permanent Address:");
this.add(padd);
padd.setBounds(10,260,150,20);

pcity= new JLabel("City:");
this.add(pcity);
pcity.setBounds(10,290,150,20);

pstate= new JLabel("State:");
this.add(pstate);
pstate.setBounds(500,290,150,20);

pcountry= new JLabel("Country:");
this.add(pcountry);
pcountry.setBounds(10,320,150,20);

ppincode= new JLabel("Pincode:");
this.add(ppincode);
ppincode.setBounds(500,320,150,20);

mobileno= new JLabel("Mobile No:");
this.add(mobileno);
mobileno.setBounds(10,350,150,20);

phone= new JLabel("Phone:");
this.add(phone);
phone.setBounds(500,350,150,20);

email= new JLabel("Email ID:");
this.add(email);
email.setBounds(10,380,150,20);

martial= new JLabel("Martial Status:");
this.add(martial);
martial.setBounds(500,380,100,20);

idmark1= new JLabel("Identification Mark1:");
this.add(idmark1);
idmark1.setBounds(10,410,150,20);

idmark2= new JLabel(" Mark2:");
this.add(idmark2);
idmark2.setBounds(10,440,150,20);

blood= new JLabel("Blood Group/RH Group:");
this.add(blood);
blood.setBounds(10,470,150,20);

reffer= new JLabel("Reffered By:");
this.add(reffer);
reffer.setBounds(500,470,150,20);

allergy= new JLabel("History of Allergies:");
this.add(allergy);
allergy.setBounds(10,500,150,20);

nation= new JLabel("Nationality:");
this.add(nation);
nation.setBounds(500,500,150,20);

insholder= new JLabel("Insurance Holder(if any):");
this.add(insholder);
insholder.setBounds(10,530,150,20);

inscompany= new JLabel("Insurance Company:");
this.add(inscompany);
inscompany.setBounds(10,560,150,20);

policy= new JLabel("Policy No:");
this.add(policy);
policy.setBounds(500,560,150,20);

person= new JLabel("Person to Contact at Emergency:");
this.add(person);
person.setBounds(10,590,200,20);

relation= new JLabel("Relationship:");
this.add(relation);
relation.setBounds(500,590,150,20);

sign= new JLabel("Patient or Gaurdian Signature:");;
this.add(sign);
sign.setBounds(10,620,180,20);

tregist= new JTextField();
tregist.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tregist);
tregist.setBounds(200,20,150,20);

tdate1= new JTextField();
tdate1.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tdate1);
tdate1.setBounds(200,50,150,20);

tphoto= new JLabel();
this.add(tphoto);
tphoto.setBounds(600,5,150,130);
tphoto.setCursor(new Cursor(Cursor.HAND_CURSOR));
tphoto.setBorder(BorderFactory.createLineBorder(Color.black));
tphoto.setOpaque(true);
tphoto.setBackground(Color.WHITE);
tphoto.addMouseListener(this);

ctitle= new JComboBox();
//ctitle.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(ctitle);
ctitle.addItem("Mr.");
ctitle.addItem("Ms.");
ctitle.addItem("Master.");
ctitle.setBounds(200,80,150,20);

toof= new JTextField();
toof.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(toof);
toof.setBounds(200,110,150,20);

tdob= new JTextField();
tdob.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tdob);
tdob.setBounds(200,140,150,20);

csex= new JComboBox();
//csex.setBorder(BorderFactory.createLineBorder(Color.black));
csex.addItem("Male");
csex.addItem("Female");
this.add(csex);
csex.setBounds(600,140,150,20);

tcadd= new JTextField();
tcadd.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tcadd);
tcadd.setBounds(200,170,550,20);

tccity= new JTextField();
tccity.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tccity);
tccity.setBounds(200,200,150,20);

tcstate= new JTextField();
tcstate.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tcstate);
tcstate.setBounds(600,200,150,20);

tccountry= new JTextField();
tccountry.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tccountry);
tccountry.setBounds(200,230,150,20);

tcpincode= new JTextField();
tcpincode.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tcpincode);
tcpincode.setBounds(600,230,150,20);

tpadd= new JTextField();
tpadd.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tpadd);
tpadd.setBounds(200,260,550,20);

tpcity= new JTextField();
tpcity.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tpcity);
tpcity.setBounds(200,290,150,20);

tpstate= new JTextField();
tpstate.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tpstate);
tpstate.setBounds(600,290,150,20);

tpcountry= new JTextField();
tpcountry.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tpcountry);
tpcountry.setBounds(200,320,150,20);

tppincode= new JTextField();
tppincode.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tppincode);
tppincode.setBounds(600,320,150,20);

tmobileno= new JTextField();
tmobileno.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tmobileno);
tmobileno.setBounds(200,350,150,20);

tphone= new JTextField();
tphone.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tphone);
tphone.setBounds(600,350,150,20);

temail= new JTextField();
temail.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(temail);
temail.setBounds(200,380,150,20);

cmartial= new JComboBox();
//cmartial.setBorder(BorderFactory.createLineBorder(Color.black));
cmartial.addItem("Single");
cmartial.addItem("Married");
cmartial.addItem("Widower");
cmartial.addItem("Divorced");
this.add(cmartial);
cmartial.setBounds(600,380,150,20);

tidmark1= new JTextField();
tidmark1.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tidmark1);
tidmark1.setBounds(200,410,550,20);

tidmark2= new JTextField();
tidmark2.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tidmark2);
tidmark2.setBounds(200,440,550,20);

tblood= new JTextField();
tblood.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tblood);
tblood.setBounds(200,470,150,20);

treffer= new JTextField();
this.add(treffer);
treffer.setBorder(BorderFactory.createLineBorder(Color.black));
treffer.setBounds(600,470,150,20);

tallergy= new JTextField();
tallergy.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tallergy);
tallergy.setBounds(200,500,150,20);

tnation= new JTextField();
this.add(tnation);
tnation.setBorder(BorderFactory.createLineBorder(Color.black));
tnation.setBounds(600,500,150,20);

tinsholder= new JTextField();
tinsholder.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tinsholder);
tinsholder.setBounds(200,530,150,20);

tinscompany= new JTextField();
tinscompany.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tinscompany);
tinscompany.setBounds(200,560,150,20);

tpolicy= new JTextField();
tpolicy.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(tpolicy);
tpolicy.setBounds(600,560,150,20);

tperson= new JTextField();
this.add(tperson);
tperson.setBorder(BorderFactory.createLineBorder(Color.black));
tperson.setBounds(200,590,150,20);

trelation= new JTextField();
this.add(trelation);
trelation.setBorder(BorderFactory.createLineBorder(Color.black));
trelation.setBounds(600,590,150,20);

tsign= new JTextField();
this.add(tsign);
tsign.setBorder(BorderFactory.createLineBorder(Color.black));
tsign.setBounds(200,620,150,20);

browse= new JButton("Browse");
browse.setBounds(750,50,100,20);
//this.add(browse);
browse.addActionListener(this);

register=new JButton("Register");
register.setBounds(20,660,150,30);
this.add(register);
register.addActionListener(this);

reset=new JButton("Reset");
reset.setBounds(220,660,150,30);
this.add(reset);
reset.addActionListener(this);

cancel=new JButton("Cancel");
cancel.setBounds(420,660,150,30);
this.add(cancel);
cancel.addActionListener(this);

print=new JButton("Print");
print.setBounds(620,660,150,30);
this.add(print);
print.addActionListener(this);

search=new JButton("Search");
search.setBounds(820,660,150,30);
this.add(search);
search.addActionListener(this);;

this.setLayout(null);
this.setTitle("Patient Registration Form");
this.setSize(1024,738);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setVisible(true);
this.setResizable(true);
this.show();
reformat();

}
public void reformat() {
Date today = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
try {
String dateString = formatter.format(today);
tdate1.setText(dateString);
} catch (IllegalArgumentException iae) {
tdate1.setForeground(Color.red);
tdate1.setText("Error: " + iae.getMessage());
}
}

public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==reset)
{
tregist.setText("");
toof.setText("");
tnation.setText("");
tdob.setText("");
tccity.setText("");
tcstate.setText("");
tccountry.setText("");
tcpincode.setText("");
tpcity.setText("");
tpstate.setText("");
tpcountry.setText("");
tppincode.setText("");
tmobileno.setText("");
tphone.setText("");
temail.setText("");
tblood.setText("");
treffer.setText("");
tallergy.setText("");
tinsholder.setText("");
tinscompany.setText("");
tpolicy.setText("");
tperson.setText("");
trelation.setText("");
tsign.setText("");
tcadd.setText("");
tpadd.setText("");
tidmark1.setText("");
tidmark2.setText("");

}}
public static void main(String args[]){
new register();
}
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub

}
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub

}
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub

}
public void mousePressed(MouseEvent e) {
if(e.getSource()==tphoto){
try
{

FileDialog fd=new FileDialog(this,"Open",FileDialog.LOAD);
fd.show();
FileInputStream fos=new FileInputStream(fd.getDirectory()+fd.getFile());
System.out.println(fd.getDirectory()+fd.getFile());
int b;
sBrowseImage=String.valueOf(fd.getDirectory()+fd.getFile());
// while((b=fos.read())!=-1)
// {
// sBrowseImage+=(char)b;
// }
System.out.println("the sbrowse value is"+sBrowseImage);
//tphoto.setText(sBrowseImage);
tphoto.setIcon(new ImageIcon(sBrowseImage));
fos.close();
}catch(Exception ee){
JOptionPane.showMessageDialog(this, ee, "Browse Error", JOptionPane.ERROR_MESSAGE);}

}

}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub

}

}

No comments: