/**
* @(#)SimpleFormDemo.java
*
*
* @author - anant mahale
* @version 1.00 2013/3/20
*/
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class SimpleForm extends Frame implements ItemListener,ActionListener
{
private Label lbl_fname,lbl_lname,lbl_add,lbl_date,lbl_sex,lbl_games,lbl_e_mailid,lbl_aboutyou,lbl_at,lbl_com;
private Button btn_submit,btn_clear,btn_close,btn_load;
private TextField txt_fname,txt_lname,txt_e_mailid;
private Choice ch_date,ch_month,ch_year,ch_email_site;
private TextArea txta_result,txta_address,txta_aboutyou;
private Checkbox chb_male,chb_female,chb_crickate,chb_football,chb_volleyball;
private CheckboxGroup cg=new CheckboxGroup();
private int birth_day,birth_month,birth_year;
private String str_email="";
public SimpleForm()
{
setBackground(Color.LIGHT_GRAY);
setLayout(null);
setTitle("Application Form");
setSize(900,730);
setLocation(0,0);
setResizable(false); // cant change windows height and width
lbl_fname=new Label("First Name");
lbl_fname.setBounds(60,100,130,20);
add(lbl_fname);
lbl_lname=new Label("Last Name");
lbl_lname.setBounds(60,150,130,20);
add(lbl_lname);
lbl_add=new Label("Address");
lbl_add.setBounds(60,200,130,20);
add(lbl_add);
txt_fname=new TextField(10);
txt_fname.setBounds(210,100,200,20);
add(txt_fname);
txt_lname=new TextField(10);
txt_lname.setBounds(210,150,200,20);
add(txt_lname);
txta_address=new TextArea();
txta_address.setBounds(210,200,200,100);
add(txta_address);
lbl_date=new Label("Date of Birth");
lbl_date.setBounds(60,350,130,20);
add(lbl_date);
ch_date=new Choice();
ch_date.add("1");
ch_date.add("2");
ch_date.add("3");
ch_date.add("4");
ch_date.add("5");
ch_date.add("6");
ch_date.add("7");
ch_date.add("8");
ch_date.add("9");
ch_date.add("10");
ch_date.add("11");
ch_date.add("12");
ch_date.add("13");
ch_date.add("14");
ch_date.add("15");
ch_date.add("16");
ch_date.add("17");
ch_date.add("18");
ch_date.add("19");
ch_date.add("20");
ch_date.add("21");
ch_date.add("22");
ch_date.add("23");
ch_date.add("24");
ch_date.add("25");
ch_date.add("26");
ch_date.add("27");
ch_date.add("28");
ch_date.add("29");
ch_date.add("30");
ch_date.add("31");
ch_date.setBounds(200,350,0,20);
ch_date.addItemListener(this);
add(ch_date);
ch_month=new Choice();
ch_month.add("1");
ch_month.add("2");
ch_month.add("3");
ch_month.add("4");
ch_month.add("5");
ch_month.add("6");
ch_month.add("7");
ch_month.add("8");
ch_month.add("9");
ch_month.add("10");
ch_month.add("11");
ch_month.add("12");
ch_month.setBounds(250,350,0,20);
ch_month.addItemListener(this);
add(ch_month);
ch_year=new Choice();
ch_year.add("1985");
ch_year.add("1986");
ch_year.add("1987");
ch_year.add("1988");
ch_year.add("1989");
ch_year.add("1990");
ch_year.add("1991");
ch_year.add("1992");
ch_year.add("1993");
ch_year.add("1994");
ch_year.add("1995");
ch_year.add("1996");
ch_year.add("1997");
ch_year.add("1998");
ch_year.add("1999");
ch_year.add("2000");
ch_year.setBounds(300,350,0,20);
ch_year.addItemListener(this);
add(ch_year);
lbl_sex=new Label("Sex");
lbl_sex.setBounds(60,400,130,20);
add(lbl_sex);
chb_male=new Checkbox("Male",cg,true);
chb_male.setBounds(200,400,100,20);
chb_male.addItemListener(this);
add(chb_male);
chb_female=new Checkbox("Female",cg,false);
chb_female.setBounds(300,400,100,20);
chb_female.addItemListener(this);
add(chb_female);
lbl_games=new Label("Fev Games");
lbl_games.setBounds(60,450,130,20);
add(lbl_games);
chb_crickate=new Checkbox("Crickate");
chb_crickate.setBounds(210,450,75,20);
chb_crickate.addItemListener(this);
add(chb_crickate);
chb_football=new Checkbox("FootBall");
chb_football.setBounds(300,450,75,20);
chb_football.addItemListener(this);
add(chb_football);
chb_volleyball=new Checkbox("VolleyBall");
chb_volleyball.setBounds(390,450,75,20);
chb_volleyball.addItemListener(this);
add(chb_volleyball);
lbl_e_mailid=new Label("E-mail-ID");
lbl_e_mailid.setBounds(60,500,130,20);
add(lbl_e_mailid);
txt_e_mailid=new TextField(10);
txt_e_mailid.setBounds(200,500,100,20);
add(txt_e_mailid);
lbl_at=new Label("@");
lbl_at.setBounds(300,500,20,20);
add(lbl_at);
ch_email_site=new Choice();
ch_email_site.add("gmail");
ch_email_site.add("yahoo");
ch_email_site.add("rediffmail");
ch_email_site.add("hotmail");
ch_email_site.setBounds(320,500,0,20);
ch_email_site.addItemListener(this);
add(ch_email_site);
lbl_com=new Label(".com");
lbl_com.setBounds(400,500,100,20);
add(lbl_com);
lbl_aboutyou=new Label("Something About You");
lbl_aboutyou.setBounds(60,550,130,20);
add(lbl_aboutyou);
txta_aboutyou=new TextArea();
txta_aboutyou.setBounds(200,550,200,100);
add(txta_aboutyou);
btn_clear=new Button("Clear");
btn_clear.addActionListener(this);
btn_clear.setBounds(225,700,100,20);
add(btn_clear);
btn_close=new Button("Close");
btn_close.addActionListener(this);
btn_close.setBounds(350,700,100,20);
add(btn_close);
btn_submit=new Button("Submit");
btn_submit.addActionListener(this);
btn_submit.setBounds(100,700,100,20);
add(btn_submit);
btn_load=new Button("Load Data");
btn_load.addActionListener(this);
btn_load.setBounds(650,700,100,20);
add(btn_load);
txta_result=new TextArea();
txta_result.setBounds(550,100,300,550);
add(txta_result);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public void paint(Graphics g)
{
g.setFont(new Font("Informal Roman",Font.BOLD,30));
g.setColor(Color.black);
g.drawString("Application Form",150,80);
g.setFont(new Font("Informal Roman",Font.BOLD,30));
g.setColor(Color.black);
g.drawString("Data",660,80);
g.drawLine(500,50,500,700);
g.drawLine(505,50,505,700);
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==ch_date)
{
int i=ch_date.getSelectedIndex();
switch(i)
{
case 0:birth_day=1;break;
case 1:birth_day=2;break;
case 2:birth_day=3;break;
case 3:birth_day=4;break;
case 4:birth_day=5;break;
case 5:birth_day=6;break;
case 6:birth_day=7;break;
case 7:birth_day=8;break;
case 8:birth_day=9;break;
case 9:birth_day=10;break;
case 10:birth_day=11;break;
case 11:birth_day=12;break;
case 12:birth_day=13;break;
case 13:birth_day=14;break;
case 14:birth_day=15;break;
case 15:birth_day=16;break;
case 16:birth_day=17;break;
case 17:birth_day=18;break;
case 18:birth_day=19;break;
case 19:birth_day=20;break;
case 20:birth_day=21;break;
case 21:birth_day=22;break;
case 22:birth_day=23;break;
case 23:birth_day=24;break;
case 24:birth_day=25;break;
case 25:birth_day=26;break;
case 26:birth_day=27;break;
case 27:birth_day=28;break;
case 28:birth_day=29;break;
case 29:birth_day=30;break;
}
}
if(ie.getSource()==ch_month)
{
int i=ch_month.getSelectedIndex();
switch(i)
{
case 0:birth_month=1;break;
case 1:birth_month=2;break;
case 2:birth_month=3;break;
case 3:birth_month=4;break;
case 4:birth_month=5;break;
case 5:birth_month=6;break;
case 6:birth_month=7;break;
case 7:birth_month=8;break;
case 8:birth_month=9;break;
case 9:birth_month=10;break;
case 10:birth_month=11;break;
case 11:birth_month=12;break;
}
}
if(ie.getSource()==ch_year)
{
int i=ch_year.getSelectedIndex();
switch(i)
{
case 0:birth_year=1985;break;
case 1:birth_year=1986;break;
case 2:birth_year=1987;break;
case 3:birth_year=1988;break;
case 4:birth_year=1989;break;
case 5:birth_year=1990;break;
case 6:birth_year=1991;break;
case 7:birth_year=1992;break;
case 8:birth_year=1993;break;
case 9:birth_year=1994;break;
case 10:birth_year=1995;break;
case 11:birth_year=1996;break;
case 12:birth_year=1997;break;
case 13:birth_year=1998;break;
case 14:birth_year=1999;break;
case 15:birth_year=2000;break;
}
}
if(ie.getSource()==ch_email_site)
{
int i=ch_email_site.getSelectedIndex();
switch(i)
{
case 0:str_email="@gamil";break;
case 1:str_email="@yahoo";break;
case 3:str_email="@rediffmail";break;
case 4:str_email="@hotmail";break;
}
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btn_submit)
{
String str_sex="",str_game="";
String str_fname,str_lname,str_e_mailid,str_add,str_fullname,str_upper_fullname,str_aboutyou;
str_fname=txt_fname.getText();
str_lname=txt_lname.getText();
str_add=txta_address.getText();
str_e_mailid=txt_e_mailid.getText();
str_aboutyou=txta_aboutyou.getText();
str_fullname=str_fname.concat(" "+str_lname);// string concatinate
str_upper_fullname=str_fullname.toUpperCase();// convert string into uppercase
if(chb_male.getState())
{
str_sex="Male";
}
else if(chb_female.getState())
{
str_sex="Female";
}
if(chb_crickate.getState()&&chb_football.getState()&&chb_volleyball.getState())
{
str_game="Cricket, Football, Vallyball";
}
else if(chb_crickate.getState()&&chb_football.getState())
{
str_game="Cricket, Football";
}
else if(chb_crickate.getState()&&chb_volleyball.getState())
{
str_game="Cricket, Vallyball";
}
else if(chb_football.getState()&&chb_volleyball.getState())
{
str_game="Football, Vallyball";
}
else if(chb_crickate.getState())
{
str_game="Cricket";
}
else if(chb_football.getState())
{
str_game="Football";
}
else if(chb_volleyball.getState())
{
str_game="Cricket";
}
txta_result.setText("Name - "+str_upper_fullname+"\n\n"+"Address - "+str_add+"\n\n"+"Date Of Birth - "+birth_day+" | "+birth_month+" | "+birth_year+"\n\n"+"Sex - "+str_sex+"\n\n"+"Game - "+str_game+"\n\n"+"E-mailID - "+str_e_mailid+""+str_email+"\n\n"+"Something About You - "+str_aboutyou);
}
if(ae.getSource()==btn_clear)
{
txt_fname.setText(" ");
txt_lname.setText(" ");
txta_address.setText(" ");
txt_e_mailid.setText(" ");
}
if(ae.getSource()==btn_close)
{
new CloseDilog().setVisible(true);
}
if(ae.getSource()==btn_load)
{
try
{
FileDialog fd=new FileDialog(this,"Save File",FileDialog.SAVE);
fd.setVisible(true);
String txt=txta_result.getText();
String dir=fd.getDirectory();
String fname=fd.getFile();
FileOutputStream fos=new FileOutputStream(dir+fname);
DataOutputStream dos=new DataOutputStream(fos);
dos.writeBytes(txt);
dos.close();
}
catch(Exception e)
{
}
}
}
}
class CloseDilog extends Dialog implements ActionListener
{
private Label lbl_msg;
private Button btn_yes,btn_no;
private Panel north_panel,south_panel;
public CloseDilog()
{
super(new SimpleForm(),"Dialogbox for Close",true);
north_panel=new Panel();
south_panel=new Panel();
setTitle("Confirm Close");
setSize(200,200);
setLocation(50,80);
lbl_msg=new Label("Do you want to Close?");
btn_yes=new Button("Yes");
btn_no=new Button("No");
north_panel.add(lbl_msg);
south_panel.add(btn_yes);
south_panel.add(btn_no);
add(north_panel,"North");
add(south_panel,"South");
btn_yes.addActionListener(this);
btn_no.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btn_yes)
{
System.exit(0);
}
else
dispose();
}
}
class SimpleFormDemo
{
public static void main(String []args)
{
new SimpleForm().setVisible(true);
}
}
No comments:
Post a Comment