Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
student registration form using swing source code
#1

package eg.DBConn;

import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.*;

public class StudInformation extends JFrame implements ActionListener
{
JTextField txt_id,txt_name,txt_age,txt_course,txt_semester,txt_tutor;
JLabel lbl_title,lbl_id,lbl_name,lbl_age,lbl_course,lbl_semester,lbl_tutor;
JButton btn_insert,btn_delete,btn_update,btn_clear,btn_search;

Connection c;

public StudInformation()
{
lbl_title=new JLabel("Student Information");
lbl_id=new JLabel("Id");
lbl_name=new JLabel("Name");
lbl_age=new JLabel("Age");
lbl_course=new JLabel("Course");
lbl_semester=new JLabel("Semester");
lbl_tutor=new JLabel("Tutor");

txt_id=new JTextField(20);
txt_name=new JTextField(20);

txt_age=new JTextField(20);
txt_course=new JTextField(20);
txt_semester=new JTextField(20);
txt_tutor=new JTextField(20);

btn_insert=new JButton("Insert");
btn_delete=new JButton("Delete");
btn_update=new JButton("Update");
btn_clear=new JButton("Clear");
btn_search=new JButton("Search");

btn_insert.addActionListener(this);
btn_delete.addActionListener(this);
btn_update.addActionListener(this);
btn_clear.addActionListener(this);
btn_search.addActionListener(this);

JPanel p1,p2,p3;

p1=new JPanel();
p1.setLayout(new FlowLayout());
p1.add(lbl_title);

p2=new JPanel();
p2.setLayout(new GridLayout(6,2));
p2.add(lbl_id);
p2.add(txt_id);
p2.add(lbl_name);
p2.add(txt_name);
p2.add(lbl_age);
p2.add(txt_age);
p2.add(lbl_course);
p2.add(txt_course);
p2.add(lbl_semester);
p2.add(txt_semester);
p2.add(lbl_tutor);
p2.add(txt_tutor);


p3=new JPanel();
p3.setLayout(new FlowLayout());
p3.add(btn_insert);
p3.add(btn_delete);
p3.add(btn_update);
p3.add(btn_clear);
p3.add(btn_search);


Container c=getContentPane();
c.setLayout(null);
p1.setBounds(20,20,300,40);
p2.setBounds(10,80,200,320);
p3.setBounds(10,400,300,80);

c.add(p1);
c.add(p2);
c.add(p3);
}

public void actionPerformed(ActionEvent ae)
{

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c=DriverManager.getConnection("jdbc:odbcConfusedtud");
}
catch(Exception ex)
{
}
String btn=ae.getActionCommand();
if(btn.equals("Clear"))
{

txt_id.setText("");
txt_name.setText("");
txt_age.setText("");
txt_course.setText("");
txt_semester.setText("");
txt_tutor.setText("");
}
if(btn.equals("Search"))
{
String id=txt_id.getText();
try{
String query1="Select *from stud where id='"+id+"'";
Statement st=c.createStatement();
ResultSet rs=st.executeQuery(query1);
while(rs.next())
{
txt_id.setText(rs.getString("id"));
txt_name.setText(rs.getString("name"));
txt_age.setText(rs.getString("age"));
txt_course.setText(rs.getString("course"));
txt_semester.setText(rs.getString("semester"));
txt_tutor.setText(rs.getString("tutor"));

}
}
catch(Exception ex)
{
}
}
if(btn.equals("Update"))
{
String s1=txt_id.getText();
String s2=txt_name.getText();
String s3=txt_age.getText();
String s4=txt_course.getText();
String s5=txt_semester.getText();
String s6=txt_tutor.getText();
try{
PreparedStatement ps=c.prepareStatement("Update stud set id=?,name=?,age=?,course=?,semester=?,tutor=? where id=?");
ps.setString(1,s1);
ps.setString(2,s2);
ps.setString(3,s3);
ps.setString(4,s4);
ps.setString(5,s5);
ps.setString(6,s6);
ps.setString(7,s1);
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Successfully Updated");
txt_id.setText("");
txt_name.setText("");
txt_age.setText("");
txt_course.setText("");
txt_semester.setText("");
txt_tutor.setText("");
}
catch(Exception ex)
{
}
}
if(btn.equals("Delete"))
{
String s1=txt_id.getText();
try{
PreparedStatement ps=c.prepareStatement("Delete *from stud where id=?");
ps.setString(1,s1);
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Successfully deleted");
txt_id.setText("");
txt_name.setText("");
txt_age.setText("");
txt_course.setText("");
txt_semester.setText("");
txt_tutor.setText("");
}
catch(Exception ex)
{
}
}
if(btn.equals("Insert"))
{
String s1=txt_id.getText();
String s2=txt_name.getText();
String s3=txt_age.getText();
String s4=txt_course.getText();
String s5=txt_semester.getText();
String s6=txt_tutor.getText();
try{
PreparedStatement ps=c.prepareStatement("insert into stud values(?,?,?,?,?,?)");
ps.setString(1,s1);
ps.setString(2,s2);
ps.setString(3,s3);
ps.setString(4,s4);
ps.setString(5,s5);
ps.setString(6,s6);
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Successfully Inserted");
txt_id.setText("");
txt_name.setText("");
txt_age.setText("");
txt_course.setText("");
txt_semester.setText("");
txt_tutor.setText("");
}
catch(Exception ex)
{
}

}



}

public static void main(String args[])
{
StudInformation stud=new StudInformation();
stud.setVisible(true);
stud.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
stud.setSize(new Dimension(400,520));
}
}
package eg.DBConn;

import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.*;

public class StudInformation extends JFrame implements ActionListener
{
JTextField txt_id,txt_name,txt_age,txt_course,txt_semester,txt_tutor;
JLabel lbl_title,lbl_id,lbl_name,lbl_age,lbl_course,lbl_semester,lbl_tutor;
JButton btn_insert,btn_delete,btn_update,btn_clear,btn_search;

Connection c;

public StudInformation()
{
lbl_title=new JLabel("Student Information");
lbl_id=new JLabel("Id");
lbl_name=new JLabel("Name");
lbl_age=new JLabel("Age");
lbl_course=new JLabel("Course");
lbl_semester=new JLabel("Semester");
lbl_tutor=new JLabel("Tutor");

txt_id=new JTextField(20);
txt_name=new JTextField(20);

txt_age=new JTextField(20);
txt_course=new JTextField(20);
txt_semester=new JTextField(20);
txt_tutor=new JTextField(20);

btn_insert=new JButton("Insert");
btn_delete=new JButton("Delete");
btn_update=new JButton("Update");
btn_clear=new JButton("Clear");
btn_search=new JButton("Search");

btn_insert.addActionListener(this);
btn_delete.addActionListener(this);
btn_update.addActionListener(this);
btn_clear.addActionListener(this);
btn_search.addActionListener(this);

JPanel p1,p2,p3;

p1=new JPanel();
p1.setLayout(new FlowLayout());
p1.add(lbl_title);

p2=new JPanel();
p2.setLayout(new GridLayout(6,2));
p2.add(lbl_id);
p2.add(txt_id);
p2.add(lbl_name);
p2.add(txt_name);
p2.add(lbl_age);
p2.add(txt_age);
p2.add(lbl_course);
p2.add(txt_course);
p2.add(lbl_semester);
p2.add(txt_semester);
p2.add(lbl_tutor);
p2.add(txt_tutor);


p3=new JPanel();
p3.setLayout(new FlowLayout());
p3.add(btn_insert);
p3.add(btn_delete);
p3.add(btn_update);
p3.add(btn_clear);
p3.add(btn_search);


Container c=getContentPane();
c.setLayout(null);
p1.setBounds(20,20,300,40);
p2.setBounds(10,80,200,320);
p3.setBounds(10,400,300,80);

c.add(p1);
c.add(p2);
c.add(p3);
}

public void actionPerformed(ActionEvent ae)
{

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c=DriverManager.getConnection("jdbc:odbcConfusedtud");
}
catch(Exception ex)
{
}
String btn=ae.getActionCommand();
if(btn.equals("Clear"))
{

txt_id.setText("");
txt_name.setText("");
txt_age.setText("");
txt_course.setText("");
txt_semester.setText("");
txt_tutor.setText("");
}
if(btn.equals("Search"))
{
String id=txt_id.getText();
try{
String query1="Select *from stud where id='"+id+"'";
Statement st=c.createStatement();
ResultSet rs=st.executeQuery(query1);
while(rs.next())
{
txt_id.setText(rs.getString("id"));
txt_name.setText(rs.getString("name"));
txt_age.setText(rs.getString("age"));
txt_course.setText(rs.getString("course"));
txt_semester.setText(rs.getString("semester"));
txt_tutor.setText(rs.getString("tutor"));

}
}
catch(Exception ex)
{
}
}
if(btn.equals("Update"))
{
String s1=txt_id.getText();
String s2=txt_name.getText();
String s3=txt_age.getText();
String s4=txt_course.getText();
String s5=txt_semester.getText();
String s6=txt_tutor.getText();
try{
PreparedStatement ps=c.prepareStatement("Update stud set id=?,name=?,age=?,course=?,semester=?,tutor=? where id=?");
ps.setString(1,s1);
ps.setString(2,s2);
ps.setString(3,s3);
ps.setString(4,s4);
ps.setString(5,s5);
ps.setString(6,s6);
ps.setString(7,s1);
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Successfully Updated");
txt_id.setText("");
txt_name.setText("");
txt_age.setText("");
txt_course.setText("");
txt_semester.setText("");
txt_tutor.setText("");
}
catch(Exception ex)
{
}
}
if(btn.equals("Delete"))
{
String s1=txt_id.getText();
try{
PreparedStatement ps=c.prepareStatement("Delete *from stud where id=?");
ps.setString(1,s1);
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Successfully deleted");
txt_id.setText("");
txt_name.setText("");
txt_age.setText("");
txt_course.setText("");
txt_semester.setText("");
txt_tutor.setText("");
}
catch(Exception ex)
{
}
}
if(btn.equals("Insert"))
{
String s1=txt_id.getText();
String s2=txt_name.getText();
String s3=txt_age.getText();
String s4=txt_course.getText();
String s5=txt_semester.getText();
String s6=txt_tutor.getText();
try{
PreparedStatement ps=c.prepareStatement("insert into stud values(?,?,?,?,?,?)");
ps.setString(1,s1);
ps.setString(2,s2);
ps.setString(3,s3);
ps.setString(4,s4);
ps.setString(5,s5);
ps.setString(6,s6);
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Successfully Inserted");
txt_id.setText("");
txt_name.setText("");
txt_age.setText("");
txt_course.setText("");
txt_semester.setText("");
txt_tutor.setText("");
}
catch(Exception ex)
{
}

}



}

public static void main(String args[])
{
StudInformation stud=new StudInformation();
stud.setVisible(true);
stud.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
stud.setSize(new Dimension(400,520));
}
}
Reply

#2
I want to create a windows appliation is java using Swing in Netbeans. I want to create the student maintenance details, Mysql as backend. I dont know how to load the frames in single form. Example, if the user give user name and password in the text box and then click the login button, it will load the next frame in same form like web application.
Reply

#3
registration form of a student containing name,dob,age in swings
Reply

#4
seamless handoff with multiple radios 802.11 wlans ns2 code
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.