Ajp 15 20

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Code:

import java.awt.Container; c.add(txtSubcode);


import java.awt.event.ActionListener; c.add(lblSubName);
import java.awt.GridLayout; c.add(txtSubName);
import java.awt.event.ActionEvent; c.add(lblCredit);
import java.sql.Connection; c.add(txtCredit);
import java.sql.DriverManager; c.add(lblMaxmark);
import java.sql.PreparedStatement; c.add(txtMaxmark);
import javax.swing.JButton; c.add(lblType);
Import javax.swing.JComboBox; c.add(cmbType);
import javax.swing.JInternalFrame; c.add(lblPract);
import javax.swing.JLabel; c.add(cmbPract);
import javax.swing.JOptionPane; c.add(btnSave);
import javax.swing.JTextField; c.add(btnCancel);

public class AddSubjects extends JInternalFrame btnSave.addActionListener(this);


implements ActionListener{ btnCancel.addActionListener(this);
private JLabel }//constructor closed
lblSubcode,lblSubName,lblCredit,lblMaxmark,lblType,lbl
P ract;
private JTextField public void actionPerformed(ActionEvent ae){
txtSubcode,txtSubName,txtCredit,txtMaxmark; if(ae.getSource()==btnSave){
private JComboBox cmbType,cmbPract; try{
private JButton btnSave,btnCancel; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
public AddSubjects(){ Connection
super("Add Subjects",false,true,false,true); con=DriverManager.getConnection("jdbc:odbc:student");
setSize(200,200); String sql="INSERT INTO Subject values(?,?,?,?,?,?)";
setLocation(400,200); PreparedStatement ps=con.prepareStatement(sql);
setDefaultCloseOperation(DISPOSE_ON_CLOSE); ps.setString(1, txtSubcode.getText());
Container c=this.getContentPane(); ps.setString(2, txtSubName.getText());
getContentPane().setLayout(new GridLayout(7,2)); ps.setInt(3, Integer.parseInt(txtCredit.getText()));
ps.setInt(4, Integer.parseInt(txtMaxmark.getText()));
lblSubcode=new JLabel(" Code"); ps.setString(5,cmbType.getSelectedItem().toString() );
lblSubName=new JLabel(" Name"); ps.setString(6, cmbPract.getSelectedItem().toString());
lblCredit=new JLabel(" Credit"); int retval=ps.executeUpdate();
lblMaxmark=new JLabel(" Max.Mark"); if(retval>0){
lblType=new JLabel(" Type"); JOptionPane.showMessageDialog(null, "Record
lblPract=new JLabel("Practical"); successfully added to database");
txtSubcode=new JTextField(); txtCredit.setText("");
txtSubName=new JTextField(); txtMaxmark.setText("");
txtCredit=new JTextField(); txtSubName.setText("");
txtMaxmark=new JTextField(); txtSubcode.setText("");
cmbType=new JComboBox(); cmbType.setSelectedIndex(0);
cmbPract=new JComboBox(); cmbPract.setSelectedIndex(0);
cmbType.addItem("COUNTING"); }
cmbType.addItem("NON COUNTING"); }catch(Exception ex){
cmbType.setSelectedIndex(0); JOptionPane.showMessageDialog(null,"Error connection
cmbPract.addItem("YES"); not established or record already
cmbPract.addItem("NO"); exists","Error",JOptionPane.ERROR_MESSAGE);
cmbPract.setSelectedIndex(0); }
btnSave=new JButton("Save"); }else if(ae.getSource()==btnCancel){
btnCancel=new JButton("Cancel"); this.dispose();
}
c.add(lblSubcode); }
}//class closed
import java.awt.BorderLayout; lblCity = new JLabel("City");
import java.awt.Color; lblDistrict = new JLabel("District");
import java.awt.event.ActionEvent; lblState = new JLabel("State");
import java.awt.event.ActionListener; lblPin = new JLabel("Pin");
import java.sql.Connection; lblYear = new JLabel("Year");
import java.sql.DriverManager; lblQualification = new JLabel("Qualification");
import java.sql.ResultSet;
import java.sql.Statement; txtName = new JTextField();
import javax.swing.ImageIcon; txtAdNo = new JTextField();
import javax.swing.JButton; txtPhNo = new JTextField();
import javax.swing.JInternalFrame; txtSex = new JTextField();
import javax.swing.JLabel; txtFatherName = new JTextField();
import javax.swing.JOptionPane; txtOccupation = new JTextField();
import javax.swing.JPanel; txtMotherName = new JTextField();
import javax.swing.JTextField; txtDOB = new JTextField();
txtAge = new JTextField();
public class Deletedetails extends JInternalFrame txtCaste = new JTextField();
implements ActionListener { txtReligion = new JTextField();
txtHouseName = new JTextField();
private JPanel panel; txtCity = new JTextField();
private JButton btnDelete, btnCancel, btnView; txtDistrict = new JTextField();
private JLabel lblName, lblAdNo, lblPhNo, lblSex, txtState = new JTextField();
lblFatherName, lblOccupation; txtPin = new JTextField();
private JLabel lblMotherName, lblDOB, lblAge, txtQualification = new JTextField();
lblCaste, lblReligion, lblHouseName; txtYear = new JTextField();
private JLabel lblCity, lblDistrict, lblState, lblPin,
lblYear, lblQualification; txtName.setEditable(false);
private JTextField txtName, txtAdNo, txtPhNo, txtPhNo.setEditable(false);
txtFatherName, txtOccupation; txtSex.setEditable(false);
private JTextField txtMotherName, txtDOB, txtAge, txtFatherName.setEditable(false);
txtCaste, txtReligion, txtHouseName; txtOccupation.setEditable(false);
private JTextField txtCity, txtDistrict, txtState, txtPin, txtMotherName.setEditable(false);
txtYear, txtQualification, txtSex; txtDOB.setEditable(false);
private Connection con; txtAge.setEditable(false);
private Statement st; txtCaste.setEditable(false);
txtReligion.setEditable(false);
public Deletedetails() { txtHouseName.setEditable(false);
super("Edit Student Registration", true, true, true, true); txtCity.setEditable(false);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); txtDistrict.setEditable(false);
this.setSize(1000, 1000); txtState.setEditable(false);
txtPin.setEditable(false);
panel = new JPanel(); txtQualification.setEditable(false);
lblAdNo = new JLabel("Admission no"); txtYear.setEditable(false);
lblName = new JLabel("Name"); btnDelete = new JButton("Delete", new
lblPhNo = new JLabel("Phone no"); ImageIcon(ClassLoader.getSystemResource("Images/delu
lblSex = new JLabel("Sex"); sr.png")));
lblFatherName = new JLabel("Father's name"); btnDelete.setEnabled(false);
lblOccupation = new JLabel("Occupation"); btnCancel = new JButton("Cancel", new
lblMotherName = new JLabel("Mother's name"); ImageIcon(ClassLoader.getSystemResource("Images/can
lblDOB = new JLabel("DOB"); cel.png")));
lblAge = new JLabel("Age"); btnView = new JButton("View", new
lblCaste = new JLabel("Caste"); ImageIcon(ClassLoader.getSystemResource("Images/vie
lblReligion = new JLabel("Religion"); w.png")));
lblHouseName = new JLabel("House Name"); btnDelete.addActionListener(this);
btnCancel.addActionListener(this); panel.add(lblFatherName);
btnView.addActionListener(this); panel.add(txtFatherName);
panel.add(lblOccupation);
panel.setLayout(null); panel.add(txtOccupation);
panel.add(lblMotherName);
lblAdNo.setBounds(100, 50, 150, 25); panel.add(txtMotherName);
txtAdNo.setBounds(200, 50, 200, 25); panel.add(lblDOB);
lblName.setBounds(100, 90, 150, 25); panel.add(txtDOB);
txtName.setBounds(200, 90, 200, 25); panel.add(lblAge);
lblPhNo.setBounds(100, 130, 150, 25);
txtPhNo.setBounds(200, 130, 200, 25); panel.add(txtAge);
lblSex.setBounds(100, 170, 150, 25); panel.add(lblCaste);
txtSex.setBounds(200, 170, 200, 25); panel.add(txtCaste);
lblFatherName.setBounds(100, 210, 150, 25); panel.add(lblReligion);
txtFatherName.setBounds(200, 210, 200, 25); panel.add(txtReligion);
lblOccupation.setBounds(100, 250, 100, 25);
txtOccupation.setBounds(200, 250, 200, 25); panel.add(lblHouseName);
lblMotherName.setBounds(100, 290, 100, 25); panel.add(txtHouseName);
txtMotherName.setBounds(200, 290, 200, 25); panel.add(lblCity);
lblDOB.setBounds(100, 330, 150, 25); panel.add(txtCity);
txtDOB.setBounds(200, 330, 200, 25); panel.add(lblDistrict);
lblCaste.setBounds(100, 370, 150, 25); panel.add(txtDistrict);
txtCaste.setBounds(200, 370, 200, 25); panel.add(lblState);
panel.add(txtState);
lblAge.setBounds(500, 90, 150, 25); panel.add(lblPin);
txtAge.setBounds(600, 90, 200, 25); panel.add(txtPin);
lblReligion.setBounds(500, 130, 100, 25); panel.add(txtYear);
txtReligion.setBounds(600, 130, 200, 25); panel.add(lblYear);
lblHouseName.setBounds(500, 170, 100, 25); panel.add(lblQualification);
txtHouseName.setBounds(600, 170, 200, 25); panel.add(txtQualification);
lblCity.setBounds(500, 210, 150, 25); panel.add(btnDelete);
txtCity.setBounds(600, 210, 200, 25); panel.add(btnCancel);
lblDistrict.setBounds(500, 250, 100, 25); panel.add(btnView);
txtDistrict.setBounds(600, 250, 200, 25); add(panel, BorderLayout.CENTER);
lblState.setBounds(500, 290, 50, 25);
txtState.setBounds(600, 290, 200, 25); try {
lblPin.setBounds(500, 330, 150, 25); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
txtPin.setBounds(600, 330, 200, 25); con =
lblYear.setBounds(500, 370, 100, 25); DriverManager.getConnection("jdbc:odbc:student");
txtYear.setBounds(600, 370, 200, 25); } catch (Exception ex) {
lblQualification.setBounds(100, 420, 80, 25); JOptionPane.showMessageDialog(null, "Error on
txtQualification.setBounds(200, 420, 600, 25); connection to database, cannot continue updation process",
btnDelete.setBounds(300, 470, 100, 25); "Error", JOptionPane.ERROR_MESSAGE);
btnCancel.setBounds(450, 470, 100, 25); }//outer try catch closed
btnView.setBounds(600, 470, 100, 25); }//constructor closed
public void actionPerformed(ActionEvent e) {
panel.add(lblAdNo); if (e.getActionCommand().equalsIgnoreCase("Delete")) {
panel.add(txtAdNo); try {
panel.add(lblName); //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
panel.add(txtName); if (e.getSource() == btnDelete) {
panel.add(lblPhNo); String sql = "DELETE FROM student WHERE RollNo="
panel.add(txtPhNo); + txtAdNo.getText();
panel.add(lblSex); st.executeUpdate(sql);
panel.add(txtSex); JOptionPane.showMessageDialog(null, "Record
successfully deleted", "Success", txtAdNo.setText("");
JOptionPane.INFORMATION_MESSAGE); txtName.setText("");
ClearForm(); txtSex.setText("");
btnDelete.setEnabled(false); txtFatherName.setText("");
}//if closed txtOccupation.setText("");
} catch (Exception ex) { txtMotherName.setText("");
JOptionPane.showMessageDialog(null, "Error on database txtPhNo.setText("");
operation", "Error", JOptionPane.ERROR_MESSAGE); txtDOB.setText("");
}//outer try catch closed txtAge.setText("");
}//if closed txtCaste.setText("");
if (e.getActionCommand().equalsIgnoreCase("View")) { txtReligion.setText("");
try { txtHouseName.setText("");
st = con.createStatement(); txtCity.setText("");
ResultSet rs = st.executeQuery("SELECT * FROM student txtDistrict.setText("");
WHERE RollNo=" + txtAdNo.getText()); txtState.setText("");
if (rs.next()) { txtPin.setText("");
txtName.setText(rs.getString("SName")); txtYear.setText("");
txtSex.setText(rs.getString("Sex")); txtQualification.setText("");
txtFatherName.setText(rs.getString("FName")); }//clearform() closed
txtMotherName.setText(rs.getString("MName")); }//class closed
txtAge.setText(rs.getString("Age")); private JLabel lblUName = new JLabel("User name");
txtOccupation.setText(rs.getString("Occupation")); private JComboBox cmbUName = new JComboBox();
txtPhNo.setText(rs.getString("phno")); private JButton btnDelete = new JButton("Delete", new
txtReligion.setText(rs.getString("Religion")); ImageIcon(ClassLoader.getSystemResource("Images/delu
txtHouseName.setText(rs.getString("Hname")); sr.png")));
txtCaste.setText(rs.getString("Caste"));
txtCity.setText(rs.getString("City")); public Deleteuser() {
txtState.setText(rs.getString("State")); super("Delete user accounts", false, true, false, true);
txtDOB.setText(rs.getDate("Dob").toString()); setBounds(350, 200, 300, 200);
txtDistrict.setText(rs.getString("District")); setDefaultCloseOperation(DISPOSE_ON_CLOSE);
txtPin.setText(rs.getString("Pin")); setLayout(null);
txtYear.setText(rs.getString("Year")); lblUName.setBounds(30, 30, 100, 30);
txtQualification.setText(rs.getString("Qualification")); cmbUName.setBounds(120, 30, 130, 25);
btnDelete.setEnabled(true); btnDelete.setBounds(100, 90, 100, 25);
} else { add(lblUName);
JOptionPane.showMessageDialog(null, "Roll No not add(cmbUName);
found in database", "Not found", add(btnDelete);
JOptionPane.INFORMATION_MESSAGE); btnDelete.addActionListener(this);
ClearForm(); LoadUserames();
btnDelete.setEnabled(false); }
}//if else closed
} catch (Exception x) { public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Error on database try {
operation,Updation failure", "Error", Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
JOptionPane.ERROR_MESSAGE); Connection con =
}//inner try catch closed DriverManager.getConnection("jdbc:odbc:student");
Statement st = con.createStatement();
}//if closed String Type;
if (e.getActionCommand().equalsIgnoreCase("Cancel")) { try {
this.dispose(); if (e.getSource() == btnDelete) {
}//if closed String sql = "delete from UAD where Username='" +
} cmbUName.getSelectedItem().toString() + "'";
st.executeUpdate(sql);
private void ClearForm() { JOptionPane.showMessageDialog(null, "Database
successfully updated", "Success", Container c = this.getContentPane();
JOptionPane.INFORMATION_MESSAGE); getContentPane().setLayout(new GridLayout(5, 2));
LoadUserames();
} lblSubcode = new JLabel("Code");
} catch (Exception x) { lblSubName = new JLabel("Name");
JOptionPane.showMessageDialog(null, "Error,Unable to lblCredit = new JLabel("Credit");
perform database operation", "Error", lblMaxmark = new JLabel("Max.Mark");
JOptionPane.ERROR_MESSAGE); cmbCode = new JComboBox();
}//inner try catch closed txtSubName = new JTextField();
} catch (Exception ex1) { txtCredit = new JTextField();
JOptionPane.showMessageDialog(null, "Error on database txtMaxmark = new JTextField();
connection, Cannot perform database operation", "Error", btnDelete = new JButton("Delete");
JOptionPane.ERROR_MESSAGE); btnCancel = new JButton("Cancel");
}//outer try catch closed
}//actionPerformed() closed c.add(lblSubcode);
private void LoadUserames() { c.add(cmbCode);
String name; c.add(lblSubName);
try { c.add(txtSubName);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); c.add(lblCredit);
Connection con = c.add(txtCredit);
DriverManager.getConnection("jdbc:odbc:student"); c.add(lblMaxmark);
Statement st = con.createStatement(); c.add(txtMaxmark);
ResultSet rs = st.executeQuery("select Username from c.add(btnDelete);
UAD"); c.add(btnCancel);
cmbUName.removeAllItems(); btnDelete.addActionListener(this);
while (rs.next()) { btnCancel.addActionListener(this);
name=rs.getString(1); cmbCode.addActionListener(this);
if (!(name.equalsIgnoreCase("admin"))) { txtCredit.setEditable(false);
cmbUName.addItem(name); txtMaxmark.setEditable(false);
} txtSubName.setEditable(false);
} loadSubjectCodes();
} catch (Exception ex) { }//constructor closed
JOptionPane.showMessageDialog(null, "Error while
loading users list, Closing window" + ex.toString()); public void actionPerformed(ActionEvent ae) {
this.dispose(); if (ae.getSource() == btnDelete) {
}//try catch clsoed try {
} if(cmbCode.getSelectedItem()==null)
}//class closed return;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
public class DelSubjects extends JInternalFrame DriverManager.getConnection("jdbc:odbc:student");
implements ActionListener { String sql = "DELETE FROM Subject WHERE
Subjectcode=?";
private JLabel lblSubcode, lblSubName, lblCredit, PreparedStatement ps = con.prepareStatement(sql);
lblMaxmark; ps.setString(1, cmbCode.getSelectedItem().toString());
private JTextField txtSubName, txtCredit, txtMaxmark; int retval = ps.executeUpdate();
private JComboBox cmbCode; if (retval > 0) {
private JButton btnDelete, btnCancel; JOptionPane.showMessageDialog(null, "Record
successfully deleted");
public DelSubjects() { cmbCode.removeActionListener(this);
super("Add Subjects", false, true, false, true); loadSubjectCodes();
setSize(200, 150); txtMaxmark.setText("");
setLocation(400, 200); txtSubName.setText("");
setDefaultCloseOperation(DISPOSE_ON_CLOSE); txtCredit.setText("");
cmbCode.addActionListener(this);
cmbCode.setSelectedIndex(0); void register()// for regitsering a new user { s = new
JFrame(); Container c = s.getContentPane();
}
} catch (Exception ex) { c.setBackground(Color.CYAN); s.setLayout(null);
JOptionPane.showMessageDialog(null, ex.toString()); s.setVisible(true); s.setSize(500,500);
} s.setTitle("Register Here");
} s.setBackground(Color.red); fname = new
if (ae.getSource() == btnCancel) { JLabel("First Name");
this.dispose(); fname.setBounds(20,50,100,20); s.add(fname);
} getfname = new JTextField();
if (ae.getSource() == cmbCode) {
getfname.setBounds(110,50,150,20);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); s.add(getfname); lname = new JLabel("Last Name");
Connection con = lname.setBounds(20,80,100,20); s.add(lname);
DriverManager.getConnection("jdbc:odbc:student"); getlname = new JTextField();
String sql = "SELECT Subjectname,CreditMark,MaxMark getlname.setBounds(110,80,150,20);
FROM Subject WHERE Subjectcode=?"; s.add(getlname);
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, cmbCode.getSelectedItem().toString());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
txtSubName.setText(rs.getString(1)); email = new JLabel("Email ID");
txtCredit.setText(String.valueOf(rs.getInt(2)));
email.setBounds(20,110,100,20); s.add(email);
txtMaxmark.setText(String.valueOf(rs.getString(3)));
} getemail = new JTextField();
getemail.setBounds(110,110,150,20);
} catch (Exception ex) { s.add(getemail);
JOptionPane.showMessageDialog(null,"Error on deletion
process","Error",JOptionPane.ERROR_MESSAGE); uname = new JLabel("Username");
}
}
uname.setBounds(20,140,100,20); s.add(uname);
} getuname = new JTextField();
getuname.setBounds(110,140,150,20);
private void loadSubjectCodes() { s.add(getuname); passwd = new
try { JLabel("Password");
cmbCode.removeAllItems(); passwd.setBounds(20,170,100,20); s.add(passwd);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); getpasswd = new JPasswordField();
Connection con = getpasswd.setBounds(110,170,150,20);
DriverManager.getConnection("jdbc:odbc:student"); s.add(getpasswd); registerme = new
String sql = "SELECT Subjectcode FROM Subject"; JButton("Register Me!!");
PreparedStatement ps = con.prepareStatement(sql);
registerme.setBounds(80,230,140,30);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
s.add(registerme);
cmbCode.addItem(rs.getString(1)); registerme.addActionListener(this);
} registerme.setForeground(Color.white);
} catch (Exception ex) { registerme.setBackground(Color.black); } public
JOptionPane.showMessageDialog(null, ex.toString()); void ip() //it will find the IP address of localhost { try
} { InetAddress addr = InetAddress.getLocalHost();
} String ipAddress = addr.getHostAddress(); disp_ip =
} new JLabel("Your IP is =>

You might also like