import java.awt.*;
import java.awt.event.*;
import java.io.*;
class form extends Frame implements ActionListener
{
private Label fname_lbl,lname_lbl,address_lbl,e_mailid_lbl;
private TextField fname_txt,lname_txt,address_txt,e_mailid_txt;
private Button submit_btn,exit_btn,clear_btn,save_btn;
private TextArea area_txta;
public form()
{
setBackground(Color.LIGHT_GRAY);
setLayout(null);
setTitle("Applicatoin Form");
setSize(650,350);
setLocation(100,100);
/*-------------Labels------------*/
fname_lbl=new Label("First Name");
fname_lbl.setBounds(25,100,100,30);
add(fname_lbl);
lname_lbl=new Label("Last Name");
lname_lbl.setBounds(25,150,100,30);
add(lname_lbl);
address_lbl=new Label("Address");
address_lbl.setBounds(25,200,100,30);
add(address_lbl);
e_mailid_lbl=new Label("E-MailID");
e_mailid_lbl.setBounds(25,250,100,30);
add(e_mailid_lbl);
/*---------------TextField----------*/
fname_txt=new TextField();
fname_txt.setBounds(125,100,150,30);
add(fname_txt);
lname_txt=new TextField();
lname_txt.setBounds(125,150,150,30);
add(lname_txt);
address_txt=new TextField();
address_txt.setBounds(125,200,150,30);
add(address_txt);
e_mailid_txt=new TextField();
e_mailid_txt.setBounds(125,250,150,30);
add(e_mailid_txt);
/*-----------------Button------------*/
submit_btn=new Button("Submit");
submit_btn.setBounds(25,300,75,30);
submit_btn.addActionListener(this);
add(submit_btn);
clear_btn=new Button("Clear");
clear_btn.setBounds(125,300,75,30);
clear_btn.addActionListener(this);
add(clear_btn);
exit_btn=new Button("Exit");
exit_btn.setBounds(225,300,75,30);
exit_btn.addActionListener(this);
add(exit_btn);
save_btn=new Button("Save");
save_btn.setBounds(450,300,75,30);
save_btn.addActionListener(this);
add(save_btn);
/*--------------TextArea-----------------*/
area_txta=new TextArea();
area_txta.setBounds(350,100,275,180);
add(area_txta);
/*---------------------------------------*/
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.blue);
g.drawString("Application Form",75,80);
g.setFont(new Font("Informal Roman",Font.BOLD,30));
g.setColor(Color.blue);
g.drawString("Data",450,80);
g.drawLine(325,25,325,325);
g.drawLine(330,25,330,325);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==submit_btn)
{
String str_fname=fname_txt.getText();
String str_lname=lname_txt.getText();
String str_add=address_txt.getText();
String str_e_mailid=e_mailid_txt.getText();
area_txta.setText("\n\n"+"First Name - "+str_fname+"\n\n"+"Last Name - "+str_lname+"\n\n"+"Address - "+str_add+"\n\n"+"E-mail Id"+str_e_mailid+"\n\n");
}
else if(ae.getSource()==exit_btn)
{
new MyDialog111().setVisible(true);
}
else if(ae.getSource()==clear_btn)
{
fname_txt.setText(" ");
lname_txt.setText(" ");
address_txt.setText(" ");
e_mailid_txt.setText(" ");
area_txta.setText(" ");
}
else if(ae.getSource()==save_btn)
{
try
{
FileOutputStream fos=new FileOutputStream("swati.txt",true);
DataOutputStream dos=new DataOutputStream(fos);
String str2="\n";
String str1=area_txta.getText();
dos.writeChars(str1+str2);
dos.close();
}
catch(Exception e){}
}
}
}
class MyDialog111 extends Dialog implements ActionListener
{
private Label lbl_msg;
private Button btn_yes,btn_no;
private Panel north_panel,south_panel;
public MyDialog111()
{
super(new form(),"Dialog Demo",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 IOForm
{
public static void main(String []args)
{
new form().setVisible(true);
}
}
No comments:
Post a Comment