Saturday, July 31, 2010

Rat in a Maze Game implemented in C CODES PROJECT

 

Compatibility Turbo C

   1: #include<conio.h>
   2: #include<stdio.h>
   3: #define SIZE 15
   4: #include<stdlib.h>
   5: void main()
   6: {
   7: int maze[SIZE][SIZE],mark[SIZE][SIZE],stack[SIZE][3];
   8: static int
   9: move[8][2]={-1,0,-1,1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
  10:  
  11: int i,j,m,n,top,mov,g,h;
  12: clrscr();
  13: printf("enter size");
  14: scanf("%d%d",&m,&n);
  15: for(i=1;i<=m;i++)
  16: {
  17: for(j=1;j<=n;j++)
  18: {
  19: scanf("%d",&maze[i][j]);
  20: }
  21: }
  22: for(i=0;i<=n+1;i++)
  23: maze[0][i]=1;
  24: for(i=0;i<=n+1;i++)
  25: maze[m+1][i]=1;
  26: for(i=0;i<=m+1;i++)
  27: maze[i][0]=1;
  28: for(i=0;i<=m+1;i++)
  29: maze[i][n+1]=1;
  30: for(i=1;i<=m;i++)
  31: {
  32: for(j=1;j<=n;j++)
  33: {
  34: mark[i][j]=0;
  35: }
  36: }
  37: mark[1][1]=1;
  38: stack[0][0]=1;
  39: stack[0][1]=1;
  40: stack[0][2]=2;
  41: top=1;
  42: while(top!=0)
  43: {
  44: i=stack[0][0];
  45: j=stack[0][1];
  46: mov=stack[0][2];
  47: top=top-1;
  48: while(mov<=7)
  49: {
  50: g=i+move[mov][0];
  51: h=j+move[mov][1];
  52:  
  53: if(mark[g][h]==0&&maze[g][h]==0)
  54: {
  55: mark[g][h]=1;
  56: top++;
  57: stack[top][0]=i;
  58: stack[top][1]=j;
  59: mov=-1;
  60: i=g;j=h;
  61: }
  62: mov=mov+1;
  63: if(g==m&&h==n)
  64: {
  65: printf("
  66: path made by the rat is");
  67: for(i=1;i<=top;i++)
  68: printf("
  69: %d %d",stack[i][0],stack[i][1]);
  70: printf("
  71: %d %d",m,n);
  72: getch();
  73: exit(0);
  74: }
  75: }
  76: }
  77: }
  78:  
  79:  
  80:  
  81:  
  82:             

STUDENT MANEGMENT PROJECT IN JAVA

 

student mgm can be used by the schools or colgs to store there student marks and check there status by there name or roll no; can be updated by adding features like checking progress or downfall in study of a student

   1: import java.io.*;
   2: import java.applet.*;
   3: import java.awt.*;
   4: import java.awt.event.*;
   5: import java.sql.*;
   6:  
   7:  
   8: public class menu extends Frame implements 
   9: WindowListener,ActionListener
  10: {
  11: MenuBar mb;
  12: MenuItem student,rollnowise,namewise,allresult;
  13: public static menu m;
  14: rollnowise rw;
  15: namewise n;
  16: student st;
  17: int x,y,d;
  18:  
  19: public menu()
  20:   {
  21:   super("menu ARPAN");
  22:   addWindowListener(this);
  23:   x=y=700;
  24:   d=10;
  25:   setSize(x,y);
  26:   setBackground(Color.orange);
  27:   addMenu();
  28:   show();
  29:   }
  30:  
  31:   public static void main(String args[])
  32:   {
  33:    m=new menu();
  34:   }
  35:  
  36:  
  37: void addMenu()
  38:  {
  39:  MenuBar mb=new MenuBar();
  40:  Menu register=new Menu("REGISTER");
  41:  Menu inquery=new Menu("INQUERY");
  42:  register.add("STUDENT");
  43:  register.add("EXIT");
  44:  inquery.add("ROLLNOWISE");
  45:  inquery.add("NAMEWISE");
  46:  
  47:   mb.add(register);
  48:   mb.add(inquery);
  49:  
  50:  setMenuBar(mb);
  51:  
  52:  register.addActionListener(this);
  53:  inquery.addActionListener(this);
  54:  
  55:  }
  56:  
  57:  
  58:  
  59:  
  60:  
  61: public void actionPerformed(ActionEvent ae)
  62:  
  63:  {
  64:  String arg=ae.getActionCommand();
  65:   if(ae.getSource() instanceof Menu)
  66:     if(arg.equals("EXIT"))
  67:       {
  68:        System.exit(0);
  69:       }
  70:   if(ae.getSource() instanceof Menu)
  71:       if("STUDENT".equals(arg))
  72:                {
  73:                 st=new student();
  74:                 st.show();
  75:                }
  76:   if(ae.getSource() instanceof Menu)
  77:     if("ROLLNOWISE".equals(arg))
  78:      {
  79:        rw=new rollnowise();
  80:        rw.show();
  81:     }
  82:    if(ae.getSource() instanceof Menu)
  83:     if("NAMEWISE".equals(arg))
  84:      {
  85:       n=new namewise();
  86:       n.show();
  87:     }
  88:   }
  89:  
  90:  
  91: public void windowClosed(WindowEvent we){}
  92: public void windowDeiconified(WindowEvent we){}
  93: public void windowIconified(WindowEvent we){}
  94: public void windowActivated(WindowEvent we){}
  95: public void windowDeactivated(WindowEvent we){}
  96: public void windowOpened(WindowEvent we){}
  97: public void windowClosing(WindowEvent we)
  98:  {
  99:  while(x>0 && y>0)
 100:   {
 101:    setSize(x,y);
 102:    x=x-d;
 103:    y=y-d;
 104:    show();
 105:   }
 106:   System.out.println("mail me at arpankumarsingh@yahoo.com");
 107:   dispose();
 108:   System.exit(0);
 109:  
 110:  }
 111: }
 112:  
 113:  
 114:  
 115:  
 116: //class for name wise report
 117:  
 118: class namewise extends Frame implements WindowListener,ActionListener
 119:   {
 120:    public static namewise nw;
 121:    Label l1=new Label("NAME",Label.LEFT);
 122:    Label l2=new Label("ROLLNO",Label.LEFT);
 123:    Label l3=new Label("COLG",Label.LEFT);
 124:    Label l4=new Label("SUB1",Label.LEFT);
 125:    Label l5=new Label("SUB2",Label.LEFT);
 126:    Label l6=new Label("SUB3",Label.LEFT);
 127:    Label l7=new Label("SUB4",Label.LEFT);
 128:    Label l8=new Label("SUB5",Label.LEFT);
 129:    TextField tf_entername=new TextField(20);
 130:    Button but_entername =new Button("FIND");
 131:    Button ok=new Button("OK");
 132:    Graphics g;
 133:    String sqlstr;
 134:    Statement st;
 135:    GridLayout gl=new GridLayout(1,2);
 136:    GridLayout cl=new GridLayout(1,5);
 137:  
 138:     Font font18=new Font("VinetaBT",Font.BOLD|Font.ITALIC,18);
 139:  
 140:     int x,y,d;
 141:     Dialog dlg;
 142:     Label msg;
 143:  
 144:     public namewise()
 145:     {
 146:     super("NAMEWISE");
 147:     addWindowListener(this);
 148:     setLayout(new GridLayout(12,1));
 149:     setBackground(Color.orange);
 150:     setForeground(Color.black);
 151:     addMenu();
 152:     x=550;
 153:  
 154:     y=450;
 155:     d=100;
 156:     setSize(x,y);
 157:     show();
 158:     }
 159:  
 160:     void addMenu()
 161:     {
 162:     Panel p4=new Panel();
 163:     Label l11=new Label("ENTERNAME");
 164:  
 165:     p4.add(l11);
 166:     p4.add(tf_entername);
 167:     p4.add(but_entername);
 168:     add(p4);
 169:  
 170:     but_entername.addActionListener(this);
 171:     ok.addActionListener(this);
 172:  
 173:  
 174:    //Dialog for confirmation
 175:  
 176:      dlg=new Dialog(this,"Inventory Management System",false);
 177:      dlg.setLayout(new GridLayout(2,1));
 178:      dlg.setSize(100,100);
 179:      dlg.setLocation(200,100);
 180:      ok.setSize(50,50);
 181:      msg=new Label("NAME NOT FOUND");
 182:      dlg.add(msg);
 183:      dlg.add(ok);
 184:  
 185:      }
 186:  
 187:  
 188:   public void actionPerformed(ActionEvent e)
 189:    {
 190:    Panel p1=new Panel();
 191:    l1.setFont(font18);
 192:    l2.setFont(font18);
 193:    p1.setLayout(gl);
 194:    p1.add(l1);
 195:    p1.add(l2);
 196:    g=getGraphics();
 197:    g.drawLine(40,0,40,0);
 198:  
 199:    Panel p2=new Panel();
 200:    l3.setFont(font18);
 201:    p2.add(l3);
 202:    p2.setLayout(gl);
 203:  
 204:    Panel p3=new Panel();
 205:    l4.setFont(font18);
 206:    l5.setFont(font18);
 207:    l6.setFont(font18);
 208:    l7.setFont(font18);
 209:    l8.setFont(font18);
 210:  
 211:   p3.add(l4);
 212:   p3.add(l5);
 213:   p3.add(l6);
 214:   p3.add(l7);
 215:   p3.add(l8);
 216:   p3.setLayout(cl);
 217:  
 218:  
 219:   String arg=e.getActionCommand();
 220:    if(e.getSource() instanceof Button)
 221:     if("FIND".equals(arg))
 222:     try
 223:      {
 224:      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 225:      Connection   
 226: con=DriverManager.getConnection("jdbc:odbc:stu","","");
 227:      sqlstr="select * from  stu1 where NAME='"+
 228: tf_entername.getText()+"'";
 229:      st=con.createStatement();
 230:      ResultSet rs;
 231:      rs= st.executeQuery(sqlstr);
 232:  
 233:         while(rs.next())
 234:      {
 235:       Panel a1=new Panel();
 236:       l1=new Label("",Label.LEFT);
 237:       l2=new Label("",Label.LEFT);
 238:       l1.setFont(font18);
 239:       l2.setFont(font18);
 240:       a1.setLayout(gl);
 241:  
 242:       Panel a2=new Panel();
 243:       l3=new Label("",Label.LEFT);
 244:       l3.setFont(font18);
 245:       a2.setLayout(gl);
 246:  
 247:       Panel a3=new Panel();
 248:       l4=new Label("",Label.LEFT);
 249:       l5=new Label("",Label.LEFT);
 250:       l6=new Label("",Label.LEFT);
 251:       l7=new Label("",Label.LEFT);
 252:       l8=new Label("",Label.LEFT);
 253:       l4.setFont(font18);
 254:  
 255:        l5.setFont(font18);
 256:  
 257:        l6.setFont(font18);
 258:  
 259:        l7.setFont(font18);
 260:  
 261:        l8.setFont(font18);
 262:        a3.setLayout(cl);
 263:  
 264:       l1.setText(rs.getString("NAME"));
 265:       l2.setText(""+rs.getInt("ROLLNO"));
 266:       l3.setText(rs.getString("COLG"));
 267:       l4.setText(""+rs.getInt("SUB1"));
 268:       l5.setText(""+rs.getInt("SUB2"));
 269:       l6.setText(""+rs.getInt("SUB3"));
 270:       l7.setText(""+rs.getInt("SUB4"));
 271:       l8.setText(""+rs.getInt("SUB5"));
 272:  
 273:      a1.add(l1);
 274:      a1.add(l2);
 275:  
 276:      a2.add(l3);
 277:  
 278:  
 279:      a3.add(l4);
 280:      a3.add(l5);
 281:      a3.add(l6);
 282:      a3.add(l7);
 283:      a3.add(l8);
 284:  
 285:      add(p1);
 286:      add(a1);
 287:  
 288:      add(p2);
 289:      add(a2);
 290:  
 291:      add(p3);
 292:      add(a3);
 293:     show();
 294:      }
 295:    }
 296:    catch(ClassNotFoundException se)
 297:     {
 298:      tf_entername.setText("Error : " + se.toString());
 299:  
 300:     }
 301:     catch(SQLException se)
 302:     {
 303:       tf_entername.setText("Error : " + se.toString());
 304:  
 305:     }
 306:  }
 307:  
 308: public void windowClosed(WindowEvent we){}
 309: public void windowDeiconified(WindowEvent we){}
 310: public void windowIconified(WindowEvent we){}
 311: public void windowActivated(WindowEvent we){}
 312: public void windowDeactivated(WindowEvent we){}
 313: public void windowOpened(WindowEvent we){}
 314:  
 315: public void windowClosing(WindowEvent we)
 316:  {
 317:   while(x>0 && y>0)
 318:   {
 319:   setSize(x,y);
 320:   x=x-d;
 321:   y=y-d;
 322:   show();
 323:   }
 324:  dispose();
 325:  
 326: }
 327: }
 328:  
 329:  
 330: //class for rollnowise report
 331:  class rollnowise extends Frame implements 
 332: WindowListener,ActionListener
 333:  {
 334:  
 335:   public static rollnowise rw;
 336:   Label l1=new Label("NAME",Label.LEFT);
 337:   Label l2=new Label("ROLLNO",Label.LEFT);
 338:   Label l3=new Label("COLG",Label.LEFT);
 339:   Label l4=new Label("SUB1",Label.LEFT);
 340:   Label l5=new Label("SUB2",Label.LEFT);
 341:   Label l6=new Label("SUB3",Label.LEFT);
 342:   Label l7=new Label("SUB4",Label.LEFT);
 343:   Label l8=new Label("SUB5",Label.LEFT);
 344:   TextField tf_entername=new TextField(20);
 345:   Button but_entername =new Button("FIND");
 346:   String sqlstr;
 347:   Statement st;
 348:   GridLayout gl=new GridLayout(1,2);
 349:   GridLayout cl=new GridLayout(1,5);
 350:  
 351:   Font font18=new Font("VinetaBT",Font.BOLD|Font.ITALIC,18);
 352:  
 353:   int x,y,d;
 354:  
 355:  
 356:  public rollnowise()
 357:  {
 358:  super("ROLLNOWISE");
 359:  addWindowListener(this);
 360:  setLayout(new GridLayout(12,1));
 361:  setBackground(Color.orange);
 362:  setForeground(Color.black);
 363:  addMenu();
 364:  x=550;
 365:  y=450;
 366:  d=100;
 367:  setSize(x,y);
 368:  show();
 369:  }
 370:  
 371:  
 372:  
 373:  void addMenu()
 374:  {
 375:  Panel p4=new Panel();
 376:  Label l11=new Label("ENTERROLLNO");
 377:  
 378:   p4.add(l11);
 379:   p4.add(tf_entername);
 380:   p4.add(but_entername);
 381:   add(p4);
 382:  
 383:  but_entername.addActionListener(this);
 384:  }
 385:  
 386:  public void actionPerformed(ActionEvent e)
 387: {
 388:  Panel p1=new Panel();
 389:  l1.setFont(font18);
 390:  l2.setFont(font18);
 391:  p1.setLayout(gl);
 392:  
 393:  
 394:  p1.add(l1);
 395:  p1.add(l2);
 396:  l3.setFont(font18);
 397:  Panel p2=new Panel();
 398:  p2.add(l3);
 399:  p2.setLayout(gl);
 400:  
 401:  Panel p3=new Panel();
 402:  
 403:  l4.setFont(font18);
 404:  
 405:  l5.setFont(font18);
 406:  
 407:  l6.setFont(font18);
 408:  
 409:  l7.setFont(font18);
 410:  
 411:  l8.setFont(font18);
 412:   p3.add(l4);
 413:   p3.add(l5);
 414:   p3.add(l6);
 415:   p3.add(l7);
 416:   p3.add(l8);
 417:   p3.setLayout(cl);
 418:  
 419: /* Panel p4=new Panel();
 420:  Label l11=new Label("ENTERROLLNO");
 421: 
 422:  p4.add(l11);
 423:  p4.add(tf_entername);
 424:  p4.add(but_entername);
 425:  add(p4);
 426:  add(p1);
 427:  add(p2);
 428:  add(p3);
 429: */
 430:   String arg=e.getActionCommand();
 431:   if(e.getSource() instanceof Button)
 432:    if("FIND".equals(arg))
 433:    try
 434:     {
 435:      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 436:      Connection   
 437: con=DriverManager.getConnection("jdbc:odbc:stu","","");
 438:      sqlstr="select * from  stu1 where ROLLNO="+
 439: tf_entername.getText()+"";
 440:      st=con.createStatement();
 441:      ResultSet rs;
 442:      rs= st.executeQuery(sqlstr);
 443:  
 444:  
 445:     while(rs.next())
 446:      {
 447:       Panel a1=new Panel();
 448:       l1=new Label("",Label.LEFT);
 449:       l2=new Label("",Label.LEFT);
 450:         l1.setFont(font18);
 451:          l2.setFont(font18);
 452:        a1.setLayout(gl);
 453:  
 454:       Panel a2=new Panel();
 455:       l3=new Label("",Label.LEFT);
 456:       l3.setFont(font18);
 457:       a2.setLayout(gl);
 458:  
 459:       Panel a3=new Panel();
 460:       l4=new Label("",Label.LEFT);
 461:       l5=new Label("",Label.LEFT);
 462:       l6=new Label("",Label.LEFT);
 463:       l7=new Label("",Label.LEFT);
 464:       l8=new Label("",Label.LEFT);
 465:       l4.setFont(font18);
 466:  
 467:        l5.setFont(font18);
 468:  
 469:        l6.setFont(font18);
 470:  
 471:        l7.setFont(font18);
 472:  
 473:         l8.setFont(font18);
 474:        a3.setLayout(cl);
 475:  
 476:       l1.setText(rs.getString("NAME"));
 477:       l2.setText(""+rs.getInt("ROLLNO"));
 478:       l3.setText(rs.getString("COLG"));
 479:       l4.setText(""+rs.getInt("SUB1"));
 480:       l5.setText(""+rs.getInt("SUB2"));
 481:       l6.setText(""+rs.getInt("SUB3"));
 482:       l7.setText(""+rs.getInt("SUB4"));
 483:       l8.setText(""+rs.getInt("SUB5"));
 484:  
 485:      a1.add(l1);
 486:      a1.add(l2);
 487:  
 488:      a2.add(l3);
 489:  
 490:  
 491:      a3.add(l4);
 492:      a3.add(l5);
 493:      a3.add(l6);
 494:      a3.add(l7);
 495:      a3.add(l8);
 496:  
 497:      add(p1);
 498:      add(a1);
 499:  
 500:      add(p2);
 501:      add(a2);
 502:  
 503:      add(p3);
 504:      add(a3);
 505:      show();
 506:      }
 507:    }
 508:    catch(ClassNotFoundException se)
 509:    {
 510:  
 511:  tf_entername.setText("Error : " + se.toString());
 512:    }
 513:  
 514:     catch(SQLException se)
 515:     {
 516:     tf_entername.setText("Error : " + se.toString());
 517:     }
 518:  }
 519:  
 520: public void windowClosed(WindowEvent we){}
 521: public void windowDeiconified(WindowEvent we){}
 522: public void windowIconified(WindowEvent we){}
 523: public void windowActivated(WindowEvent we){}
 524: public void windowDeactivated(WindowEvent we){}
 525: public void windowOpened(WindowEvent we){}
 526:  
 527: public void windowClosing(WindowEvent we)
 528:  {
 529:   while(x>0 && y>0)
 530:   {
 531:   setSize(x,y);
 532:   x=x-d;
 533:   y=y-d;
 534:   show();
 535:   }
 536:  dispose();
 537:  
 538: }
 539: }
 540:  
 541:  
 542: //class which help in storing records in the database
 543: class student extends Frame implements ActionListener,WindowListener
 544:  
 545: {
 546: public static student st;
 547: TextField tf_name=new TextField(20);
 548: TextField tf_rollno=new TextField(20);
 549: TextField tf_colg=new TextField(20);
 550: TextField tf_marks=new TextField(20);
 551: TextField tf_sub1=new TextField(4);
 552: TextField tf_sub2=new TextField(4);
 553: TextField tf_sub3=new TextField(4);
 554: TextField tf_sub4=new TextField(4);
 555: TextField tf_sub5=new TextField(4);
 556:  
 557:  
 558: Label l2=new Label("ROLLNO");
 559: Label l1=new Label("NAME");
 560: Label l3=new Label("MARKS");
 561: Label l4=new Label("COLG");
 562: Label l5=new Label("MARK SHEET");
 563: Label l6=new Label("SUB1");
 564: Label l7=new Label("SUB2");
 565: Label l8=new Label("SUB3");
 566: Label l9=new Label("SUB4");
 567: Label l10=new Label("SUB5");
 568: Button but_add=new Button("ADD");
 569: Button but_edit=new Button("EDIT");
 570: Button but_find=new Button("FIND");
 571: Button but_delete=new Button("DELETE");
 572: Button but_cancel=new Button("CANCEL");
 573: Button ok=new Button("OK");
 574: Dialog dlg;
 575: Label msg;
 576: int x,y,d;
 577:  
 578: public student()
 579: {
 580: super("palce");
 581: addWindowListener(this);
 582: setLayout(new GridLayout(6,1));
 583: setBackground(Color.yellow);
 584: setVisible(true);
 585: addmenu();
 586: x=550;
 587: y=450;
 588: d=12;
 589: setSize(x,y);
 590: show();
 591: }
 592:  
 593:  
 594: void addmenu()
 595: {
 596: //GridLayout gl=new GridLayout();
 597: Panel p1=new Panel();
 598: p1.add(l1);
 599: p1.add(tf_name);
 600:  
 601: p1.add(l2);
 602: p1.add(tf_rollno);
 603:  
 604: Panel p2=new Panel();
 605: p2.add(l5);
 606: Panel p3=new Panel();
 607: p3.add(but_add);
 608: p3.add(but_find);
 609: p3.add(but_cancel);
 610: p3.add(but_edit);
 611: p3.add(but_delete);
 612:  
 613:  
 614:  
 615: Panel p4=new Panel();
 616: //p4.add(l3);
 617: p4.add(l6);
 618: p4.add(l7);
 619: p4.add(l8);
 620: p4.add(l9);
 621: p4.add(l10);
 622:  
 623: Panel p8=new Panel();
 624: p8.add(tf_sub1);
 625: p8.add(tf_sub2);
 626: p8.add(tf_sub3);
 627: p8.add(tf_sub4);
 628: p8.add(tf_sub5);
 629:  
 630: Panel p5=new Panel();
 631: p5.add(l4);
 632: p5.add(tf_colg);
 633:  
 634: add(p2);
 635: add(p1);
 636: add(p5);
 637: add(p4);
 638: add(p8);
 639: add(p3);
 640: but_add.addActionListener(this);
 641: but_cancel.addActionListener(this);
 642: but_find.addActionListener(this);
 643: but_delete.addActionListener(this);
 644: but_edit.addActionListener(this);
 645:  ok.addActionListener(this);
 646: //Dialog for confirmation
 647:  
 648:      dlg=new Dialog(this,"Inventory Management System",false);
 649:      dlg.setLayout(new GridLayout(2,1));
 650:      dlg.setSize(100,100);
 651:      dlg.setLocation(200,100);
 652:      ok.setSize(50,50);
 653:      msg=new Label("Record Updated");
 654:      dlg.add(msg);
 655:      dlg.add(ok);
 656:  
 657:  
 658:  
 659: }
 660: public void actionPerformed(ActionEvent e)
 661: {
 662: String arg=e.getActionCommand();
 663: //ADDBUTTON
 664: if(e.getSource() instanceof Button)
 665:  if("ADD".equals(arg))
 666:   try
 667:   {
 668:   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 669:   Connection con=DriverManager.getConnection("jdbc:odbc:stu","","");
 670:   Statement st;
 671:  
 672:   String sqlStr;
 673:   sqlStr="insert into
 674: stu1(NAME,ROLLNO,COLG,SUB1,SUB2,SUB3,SUB4,SUB5)values('"+tf_name.getText()
 675: +"',"+tf_rollno.getText()+",'"+tf_colg.getText()+"',"+tf_sub1.getText()+",
 676: "+tf_sub2.getText()+","+tf_sub3.getText()+","+tf_sub4.getText()+","+tf_sub
 677: 5.getText()+")";
 678:   st=con.createStatement();
 679:   st.executeUpdate(sqlStr);
 680:  }
 681:  catch(ClassNotFoundException se)
 682:  {
 683:    // tf_name.setText("Error : " + se.toString());
 684:      msg.setText("ERROR");
 685:    dlg.show();
 686:  }
 687:  catch(SQLException se)
 688:  {
 689:   //  tf_name.setText("Error : " + se.toString());
 690:   msg.setText("ENTER TEXTFIELD");
 691:    dlg.show();
 692: }
 693:  
 694: //OK button
 695:  
 696:     if ( e.getSource() instanceof Button)
 697:         if ("OK".equals(arg))
 698:         { dlg.dispose();
 699:         }
 700:  //CANCEL
 701:   if(e.getSource() instanceof Button)
 702:    if("CANCEL".equals(arg))
 703:  
 704:     {
 705:     tf_name.setText("");
 706:     tf_rollno.setText("");
 707:     tf_colg.setText("");
 708:     tf_sub1.setText("");
 709:     tf_sub2.setText("");
 710:     tf_sub3.setText("");
 711:     tf_sub4.setText("");
 712:      tf_sub5.setText("");
 713:      }
 714:   //FIND
 715:    if(e.getSource() instanceof Button)
 716:     if("FIND".equals(arg))
 717:      try
 718:       {
 719:         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 720:   Connection con=DriverManager.getConnection("jdbc:odbc:stu","","");
 721:   Statement st;
 722:   String sqlstr;
 723:   sqlstr="select * from stu1 where ROLLNO ="+tf_rollno.getText()+"";
 724:   st=con.createStatement();
 725:   ResultSet rs;
 726:   rs=st.executeQuery(sqlstr);
 727:   rs.next();
 728:   tf_name.setText(""+rs.getString("NAME"));
 729:   tf_colg.setText(""+rs.getString("COLG"));
 730:   tf_sub1.setText(""+rs.getInt("SUB1"));
 731:   tf_sub2.setText(""+rs.getInt("SUB2"));
 732:   tf_sub3.setText(""+rs.getInt("SUB3"));
 733:   tf_sub4.setText(""+rs.getInt("SUB4"));
 734:   tf_sub5.setText(""+rs.getInt("SUB5"));
 735:   }
 736:  catch(ClassNotFoundException se)
 737:  {
 738:   msg.setText("RECORD NOT FOUND");
 739:    dlg.show();
 740:  
 741: //  tf_name.setText("Error : " + se.toString());
 742:  }
 743:  catch(SQLException se)
 744:  {
 745:   msg.setText("RECORD NOT FOUND");
 746:    dlg.show();
 747:   //tf_name.setText("Error : " + se.toString());
 748:  }
 749:  //DELETE
 750:  if(e.getSource() instanceof Button)
 751:   if("DELETE".equals(arg))
 752:   try
 753:    {
 754:          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 755:   Connection con=DriverManager.getConnection("jdbc:odbc:stu","","");
 756:    Statement st;
 757:    String sqlstr;
 758:   sqlstr="delete * from stu1 where ROLLNO="+tf_rollno.getText()+"";
 759:    st=con.createStatement();
 760:    st.executeUpdate(sqlstr);
 761:    tf_name.setText("");
 762:    tf_colg.setText("");
 763:    tf_sub1.setText("");
 764:    tf_sub2.setText("");
 765:    tf_sub3.setText("");
 766:    tf_sub4.setText("");
 767:    tf_sub5.setText("");
 768:  
 769:    tf_rollno.setText("");
 770:    msg.setText("RECORD DELETED");
 771:    dlg.show();
 772:  
 773:  }
 774:   catch(ClassNotFoundException se)
 775:  {
 776:     tf_name.setText("Error : " + se.toString());
 777:  }
 778:  catch(SQLException se)
 779:  {
 780:     tf_name.setText("Error : " + se.toString());
 781:  }
 782:  
 783: //EDIT
 784: if(e.getSource() instanceof Button)
 785:  if("EDIT".equals(arg))
 786:   try
 787:    {
 788:   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 789:   Connection con=DriverManager.getConnection("jdbc:odbc:stu","","");
 790:    Statement st;
 791:    String sqlstr;
 792:    sqlstr="update stu1 set
 793: NAME='"+tf_name.getText()+"',SUB1="+tf_sub1.getText()+",SUB2="+tf_sub2.get
 794: Text()+",SUB3="+tf_sub3.getText()+",SUB4="+tf_sub4.getText()+",SUB5="+tf_s
 795: ub5.getText()+",COLG='"+tf_colg.getText()+"' where
 796: ROLLNO="+tf_rollno.getText();
 797: st=con.createStatement();
 798: st.executeUpdate(sqlstr);
 799:    msg.setText("RECORD UPDATED");
 800:    dlg.show();
 801:   }
 802:  catch(ClassNotFoundException se)
 803:  {
 804:  
 805:   tf_name.setText("Error : " + se.toString());
 806:  }
 807:  catch(SQLException se)
 808:  {
 809:  
 810:   tf_name.setText("Error : " + se.toString());
 811:  }
 812:    }
 813: public void windowClosed(WindowEvent we){}
 814: public void windowDeiconified(WindowEvent we){}
 815: public void windowIconified(WindowEvent we){}
 816: public void windowActivated(WindowEvent we){}
 817: public void windowDeactivated(WindowEvent we){}
 818: public void windowOpened(WindowEvent we){}
 819: public void windowClosing(WindowEvent we)
 820:  {
 821:   while(x>0 && y>0)
 822:   {
 823:   setSize(x,y);
 824:   x=x-d;
 825:   y=y-d;
 826:   show();
 827:   }
 828:  dispose();
 829:  }
 830:  
 831: }