Student counselling management system in java
import [Link].*;
import [Link].*;
import [Link].*;
class StudAbout extends Dialog implements
WindowListener,ActionListener
{ private Button btok;
public Label lblcap;
private Panel p,p2;
public StudAbout(Frame f)
{
super(f,"About",true);
btok=new Button("OK");
p=new Panel();
p2=new Panel();
lblcap=new Label("Councellor Session Management");
[Link](lblcap);
[Link](btok);
add("Center",p);
add("South",p2);
addWindowListener(this);
[Link](this);
setTitle("About");
setSize(250,100);
Rectangle r = [Link]();
setBounds((int)([Link]()+[Link]()/2-
125),(int)([Link]()+[Link]()/2-50),250,100);
setBackground(new Color(220,200,220));
}
public void windowOpened(WindowEvent e) {}
public void windowClosing(WindowEvent e) {
dispose();}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void actionPerformed(ActionEvent e)
{
if([Link]()==btok)
{
dispose();
}
}
}
class StudMessageBox extends Dialog implements
WindowListener,ActionListener
{
private Button btok;
public Label lblcap;
private Panel p,p2;
public StudMessageBox(Frame f)
{
super(f,"Message",true);
btok=new Button("OK");
p=new Panel();
p2=new Panel();
lblcap=new Label("");
[Link](lblcap);
[Link](btok);
add("Center",p);
add("South",p2);
addWindowListener(this);
[Link](this);
setTitle("About");
Rectangle r = [Link]();
setBounds((int)([Link]()+[Link]()/2-
125),(int)([Link]()+[Link]()/2-50),250,100);
setBackground([Link]);
}
public static void Show(String msg,String title,Frame parent)
{
StudMessageBox msgbox = new
StudMessageBox(parent);
[Link](msg);
[Link](title);
[Link]();
}
public void windowOpened(WindowEvent e) {}
public void windowClosing(WindowEvent e) {
dispose();}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void actionPerformed(ActionEvent e) {
if([Link]()==btok) dispose(); }
}
class StudReport extends Frame implements WindowListener
{
private boolean flag=true;
List lstrpt;
public StudReport()
{ setLayout(null);
lstrpt=new List();
add(lstrpt);
[Link](10,40,400,300);
addWindowListener(this);
try
{
setTitle("Report");
setSize(420,350);
ResultSet rsTemp =
[Link]("Select * from tblStud");
String st="";
while([Link]())
{
st =
[Link]("StudID")+" "+
[Link]("Name")+" "+[Link]("Age")+
" "+[Link]("Class")+" "+
[Link]("Cgroup");
[Link](st);
}
}
catch(Exception e)
{
}
}
public void itemStateChanged(ItemEvent e) {}
public void windowOpened(WindowEvent e) {}
public void windowClosing(WindowEvent e) {
dispose();}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
}
class StudConnection
{
public static Connection getConnection()
{
Connection con=null;
try
{
[Link]("[Link]");
con=[Link]("jdbc:odbc:student","","");
}
catch([Link] e)
{
[Link](e);
}
return con;
}
public static ResultSet executeQuery(String stSQL) throws
Exception
{
Connection cn = getConnection();
Statement st =
[Link](ResultSet.TYPE_SCROLL_INSENSITIVE,[Link]
UR_READ_ONLY);
ResultSet rs = [Link](stSQL);
return rs;
}
public static int executeUpdate(String stSQL) throws
Exception
{
Connection cn = getConnection();
Statement st =
[Link](ResultSet.TYPE_SCROLL_INSENSITIVE,[Link]
UR_READ_ONLY);
int n = [Link](stSQL);
return n;
}
}
public class Stud extends Frame implements
WindowListener,ActionListener
{
TextField txtid,txtname,txtage;
String lbls[] = { "ID","Name","Age","Class","Group"};
Button btMove[] = { new Button("<<"),new Button("<"),
};
Button btActions[] = { new Button("New"),new
Button("Edit"),new Button("Delete"),
};
String stcurId;
MenuBar mbar;
Choice chclass;
Choice chgroup;
boolean flag;
public Connection conn;
public Statement stmt,s1;
public ResultSet rs,r1;
public Stud()
{ setLayout(null);
flag=false;
for(int i=0;i<[Link];i++)
{
Label lbl=new Label(lbls[i]);
[Link](20,60+i*30,100,20);
add(lbl);
}
for(int i=0;i<[Link];i++)
{
btMove[i].setBounds(20+i*50,220,50,20);
add(btMove[i]);
btMove[i].addActionListener(this);
}
for(int i=0;i<[Link];i++)
{
btActions[i].setBounds(270,60+i*25,60,20);
add(btActions[i]);
btActions[i].addActionListener(this);
}
add(txtid=new TextField(10));
add(txtname=new TextField(20));
add(txtage=new TextField(3));
add(chclass=new Choice());
add(chgroup=new Choice());
[Link](130,60,60,20);
[Link](130,90,120,20);
[Link](130,120,60,20);
[Link]("");
[Link]("X");
[Link]("XI");
[Link]("XII");
[Link](130,150,60,20);
[Link]("");
[Link](130,180,60,20);
mbar=new MenuBar();
Menu help=new Menu("Help");
[Link]("About...");
[Link](help).addActionListener(this);
setMenuBar(mbar);
addWindowListener(this);
[Link](this);
setSize(360,250);
loadCG();
connect();
EnableFields(false);
setBackground([Link]);
}
private void EnableFields(boolean b)
{
[Link](b);
[Link](b);
[Link](b);
[Link](b);
[Link](b);
btMove[0].setEnabled(!b);
btMove[1].setEnabled(!b);
btMove[2].setEnabled(!b);
btMove[3].setEnabled(!b);
btActions[0].setEnabled(!b);
btActions[1].setEnabled(!b);
btActions[2].setEnabled(!b);
btActions[3].setEnabled(b);
btActions[4].setEnabled(b);
btActions[5].setEnabled(!b);
}
public void windowOpened(WindowEvent e) {}
public void windowClosing(WindowEvent e) {
[Link](0);}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void connect()
{
try
{
rs=[Link]("select * from
tblStud");
if([Link]()) Display(rs);
}
catch(SQLException e)
{
[Link](e);
}
catch([Link] ex)
{
[Link]();
[Link](ex);
}
}
public void loadCG()
{
try
{
[Link]();
[Link]("");
ResultSet rs1=
[Link]("select * from tblCg");
while([Link]())
[Link]([Link](1));
[Link]();
}
catch(Exception e2) {[Link]();}
}
public void actionPerformed(ActionEvent e)
{
String stAction = [Link]();
if([Link]("About..."))
{
StudAbout a = new StudAbout(this);
[Link]();
}
else if([Link]("Report"))
{
StudReport r=new StudReport();
[Link]();
}
else if([Link]("New"))
{
EnableFields(true);
stcurId = "";
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]();
flag=true;
}
else if([Link]("Cancel"))
{
EnableFields(false);
try
{
Display(rs);
}
catch(Exception e1)
{
}
flag=false;
}
else if([Link]("Update"))
{
String sql="";
if(flag)
sql="insert into tblStud
values('"+[Link]()+"','"+
[Link]()+"',"+[Link]()+",'"+
[Link]()+"','"+
[Link]()+"')";
else
sql="update tblStud set
Name='"+[Link]()+
"',Age="+[Link]()+
",Class='"+[Link]()+
"',CGroup='"+[Link]()+"' where
StudID='"+[Link]()+"'";
try
{
ResultSet rsTemp =
[Link]("select * from tblStud Where StudID='"
+ [Link]() + "' and StudId<>'" + stcurId + "'");
if([Link]())
{
[Link]("Duplicate Id.
Try another","Invalid Id",this);
}
else
{
[Link](sql);
}
}
catch(Exception e1)
{
[Link](e1);
}
finally
{
try
{
EnableFields(false);
rs=[Link]("select * from tblStud");
if([Link]()) Display(rs);
}
catch(Exception e2)
{
[Link](e2);
}
}
}
else if([Link]("Delete"))
{
String sql;
sql="delete from tblStud where StudID
='"+[Link]()+"'";
try
{
[Link](sql);
}
catch(SQLException e1) {}
}
else if([Link]("Edit"))
{
flag=false;
EnableFields(true);
}
else
{
try
{
if([Link]()==btMove[0])
{
if([Link]())
{
Display(rs);
}
}
else if([Link]()==btMove[3])
{
if([Link]())
{
Display(rs);
}
}
else if([Link]()==btMove[2])
{
if([Link]())
{
[Link]();
[Link]("Last
Record","Error",this);
}
if([Link]())
{
Display(rs);
}
}
else if([Link]()==btMove[1])
{
if([Link]())
{ [Link]();
[Link]("First
Record","Error",this);
}
if([Link]())
{
Display(rs);
}
}
}
catch(SQLException e1)
{
}
}
}
private void Display(ResultSet rs) throws SQLException
{
stcurId = [Link](1);
[Link]([Link](2));
[Link](stcurId);
[Link]([Link]([Link](3)));
[Link]([Link](4));
[Link]([Link](5));
[Link]();
}
public String loadName(String n)
{
String name="";
try
{
ResultSet rs1=
[Link]("select Name from tblStud where
StudID='"+n+"'");
if([Link]())
name=[Link]("Name");
else
name="no such id";
}
catch(Exception e2) {}
return(name);
}
public static void main(String s1[])
{
Stud s=new Stud();
[Link]("Student Details");
[Link]();
}
}