import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
import javax.swing.JOptionPane.*;
import java.net.*;
import java.io.*;
// <APPLET code="addstudent.class" width=500 height=500> </applet>
public class addstudent extends JApplet implements ActionListener
{ JTextField fname,lname,year,month,day,address,phonenumber,enrollmentnumber;
JButton submit;
Image background;
Connection con;
Statement s;
/* init() method of applets, that gets executed first*/
public void init()
{
/*Code to set radar as the background for out main applet window */
background = getImage(getCodeBase(),"Welcome.gif");
setContentPane(new JPanel()
{
protected void paintComponent(Graphics g)
{
g.drawImage(background, 0, 0, getSize().width, getSize().height, this);
}
});
/*Background Set*/
Container contentpane = this.getContentPane();
fname = new JTextField(8);
lname = new JTextField(8);
year = new JTextField(4);
month = new JTextField(2);
day = new JTextField(2);
address = new JTextField(30);
enrollmentnumber = new JTextField(10);
phonenumber = new JTextField(10);
submit = new JButton("Submit");
contentpane.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 1;
constraints.weightx = 100;
constraints.weighty = 100;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.insets.left = 10;
constraints.anchor = GridBagConstraints.WEST;
contentpane.add(new JLabel("First Name"),constraints);
constraints.anchor = GridBagConstraints.WEST;
constraints.insets.left = 0;
constraints.gridx = 1;
constraints.gridy = 1;
contentpane.add(fname,constraints);
constraints.anchor = GridBagConstraints.CENTER;
constraints.gridx = 2;
constraints.gridy = 1;
contentpane.add(new JLabel("Last Name"),constraints);
constraints.anchor = GridBagConstraints.WEST;
constraints.gridx = 3;
constraints.gridy = 1;
contentpane.add(lname,constraints);
constraints.anchor = GridBagConstraints.NORTH;
constraints.gridx = 0;
constraints.gridy = 2;
contentpane.add(new JLabel("Date of Birth: "),constraints);
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.gridx = 1;
constraints.gridy = 2;
contentpane.add(day,constraints);
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.gridx = 1;
constraints.gridy = 2;
constraints.insets.left = 30;
contentpane.add(new JLabel("day"),constraints);
constraints.anchor = GridBagConstraints.NORTH;
constraints.gridx = 1;
constraints.gridy = 2;
//constraints.insets.left = 30;
contentpane.add(month,constraints);
constraints.anchor = GridBagConstraints.NORTH;
constraints.gridx = 1;
constraints.gridy = 2;
constraints.insets.left = 100;
contentpane.add(new JLabel("month"),constraints);
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.gridx = 2;
constraints.gridy = 2;
constraints.insets.left = 0;
contentpane.add(year,constraints);
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.gridx = 2;
constraints.gridy = 2;
constraints.insets.left = 50;
contentpane.add(new JLabel(" year"),constraints);
constraints.anchor = GridBagConstraints.WEST;
constraints.gridx = 0;
constraints.gridy = 2;
constraints.insets.left = 10;
constraints.insets.top = 25;
contentpane.add(new JLabel("Address"),constraints);
constraints.anchor = GridBagConstraints.WEST;
constraints.gridx = 1;
constraints.gridy = 2;
constraints.gridwidth = 4;
contentpane.add(address,constraints);
constraints.insets.top = 0;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.gridx = 0;
constraints.gridy = 3;
constraints.insets.left=10;
contentpane.add(new JLabel("Enrollment Number:"),constraints);
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.gridx = 1;
constraints.gridy = 3;
constraints.insets.left=23;
contentpane.add(enrollmentnumber,constraints);
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.gridx = 2;
constraints.gridy = 3;
contentpane.add(new JLabel("Phone Number: "),constraints);
constraints.anchor = GridBagConstraints.NORTH;
constraints.gridx = 2;
constraints.gridy = 3;
constraints.insets.left=85;
contentpane.add(phonenumber,constraints);
constraints.anchor = GridBagConstraints.WEST;
constraints.gridx = 0;
constraints.gridy = 6;
constraints.insets.left=220;
contentpane.add(submit,constraints);
submit.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{ if(ae.getSource()==submit)
{JOptionPane.showMessageDialog(null,"Done!!!");
try
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:projectdsn");
s = con.createStatement();
s.executeUpdate("INSET INTO Student VALUES ('1', 'saurabh', '24')");
//ResultSet rset = s.getResultSet();
con.close();
}
catch(ClassNotFoundException exp)
{System.err.println(exp);
}
catch(SQLException exp)
{System.err.println(exp);
}
}// end of if statement
}
}