Code:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class Formm extends Frame
{ Label [] l=new Label[8];
TextField[] t=new TextField[6];
TextArea a=new TextArea();
CheckboxGroup p=new CheckboxGroup();
Checkbox c1=new Checkbox("Male",p,true);
Checkbox c2=new Checkbox("Female",p,false);
Button s=new Button("Submit");
Button r=new Button("Reset");
int y=30;
Connection cp;
Statement st;
Formm()
{
setLayout(null);
setVisible(true);
for(int i=0;i<8;i++)
{
l[i]=new Label();
l[i].setBounds(30,y,100,30);
add(l[i]);
y+=40;
}
y=30;
for(int i=0;i<6;i++)
{
t[i]=new TextField();
t[i].setBounds(130,y,100,30);
add(t[i]);
y+=40;
}
a.setBounds(130,310,150,80);
add(a);
s.setBounds(50,400,50,30);
add(s);
r.setBounds(120,400,50,30);
add(r);
c1.setBounds(130,270,50,30);
add(c1);
c2.setBounds(180,270,60,30);
add(c2);
l[0].setText("Name");
l[1].setText("Email");
l[2].setText("Password");
l[3].setText("Pincode");
l[4].setText("DOB");
l[5].setText("Mobile Number");
l[6].setText("Gender");
l[7].setText("Address");
Label h=new Label("City:");
h.setBounds(300,310,50,20);
add(h);
Choice c=new Choice();
c.setBounds(350,310,100,30);
c.add("Ludhiana");
c.add("Jalandhar");
c.add("Bhatinda");
c.add("Amritsar");
c.add("Hoshiarpur");
add(c);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
try
{
Class.forName("com.mysql.jdbc.Driver");
cp=DriverManager.getConnection("jdbc:mysql://localhost/college","root","password");
st=cp.createStatement();
}
catch(Exception e)
{
System.out.println("Error"+e);
}
r.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
for(int i=0;i<6;i++)
{
t[i].setText(" ");
}
a.setText(" ");
}
});
s.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try
{
st.executeUpdate("Insert into form values('"+t[0].getText()+"','"+t[1].getText()+"','"+t[2].getText()+"','"+t[3].getText()+"','"+t[4].getText()+"','"+a.getText()+"','"+t[5].getText()+"','"+p.getSelectedCheckbox().getLabel()+"','"+c.getSelectedItem()+",) ");
}
catch(Exception ex)
{
System.out.println("Error Occured"+ex);
}
JOptionPane.showMessageDialog(null,"Record Entered");
for(int i=0;i<6;i++)
{
t[i].setText("");
}
a.setText("");
}
});
setSize(500,500);
}
public static void main(String[] nt)
{
new Formm();
}
}
Output::
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class Formm extends Frame
{ Label [] l=new Label[8];
TextField[] t=new TextField[6];
TextArea a=new TextArea();
CheckboxGroup p=new CheckboxGroup();
Checkbox c1=new Checkbox("Male",p,true);
Checkbox c2=new Checkbox("Female",p,false);
Button s=new Button("Submit");
Button r=new Button("Reset");
int y=30;
Connection cp;
Statement st;
Formm()
{
setLayout(null);
setVisible(true);
for(int i=0;i<8;i++)
{
l[i]=new Label();
l[i].setBounds(30,y,100,30);
add(l[i]);
y+=40;
}
y=30;
for(int i=0;i<6;i++)
{
t[i]=new TextField();
t[i].setBounds(130,y,100,30);
add(t[i]);
y+=40;
}
a.setBounds(130,310,150,80);
add(a);
s.setBounds(50,400,50,30);
add(s);
r.setBounds(120,400,50,30);
add(r);
c1.setBounds(130,270,50,30);
add(c1);
c2.setBounds(180,270,60,30);
add(c2);
l[0].setText("Name");
l[1].setText("Email");
l[2].setText("Password");
l[3].setText("Pincode");
l[4].setText("DOB");
l[5].setText("Mobile Number");
l[6].setText("Gender");
l[7].setText("Address");
Label h=new Label("City:");
h.setBounds(300,310,50,20);
add(h);
Choice c=new Choice();
c.setBounds(350,310,100,30);
c.add("Ludhiana");
c.add("Jalandhar");
c.add("Bhatinda");
c.add("Amritsar");
c.add("Hoshiarpur");
add(c);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
try
{
Class.forName("com.mysql.jdbc.Driver");
cp=DriverManager.getConnection("jdbc:mysql://localhost/college","root","password");
st=cp.createStatement();
}
catch(Exception e)
{
System.out.println("Error"+e);
}
r.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
for(int i=0;i<6;i++)
{
t[i].setText(" ");
}
a.setText(" ");
}
});
s.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try
{
st.executeUpdate("Insert into form values('"+t[0].getText()+"','"+t[1].getText()+"','"+t[2].getText()+"','"+t[3].getText()+"','"+t[4].getText()+"','"+a.getText()+"','"+t[5].getText()+"','"+p.getSelectedCheckbox().getLabel()+"','"+c.getSelectedItem()+",) ");
}
catch(Exception ex)
{
System.out.println("Error Occured"+ex);
}
JOptionPane.showMessageDialog(null,"Record Entered");
for(int i=0;i<6;i++)
{
t[i].setText("");
}
a.setText("");
}
});
setSize(500,500);
}
public static void main(String[] nt)
{
new Formm();
}
}
Output::