Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Sunday 15 May 2016

Applet Program : Data selection from data base and use all the basic components and Frame , ActionListener,ItemListener

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Select1 extends Frame implements ActionListener,ItemListener
{
Label l1,l2,l3,l4,l5;
Choice ch1,ch2;
TextField t1,t2,t3,t4;
Button b1,b2,b3,b4,b5;
String cnm;
int sem;
Select1()
{
l1=new Label("enter roll no to get Info... ");
l2=new Label("Name    ");
l3=new Label("Course  ");
l4=new Label("Sem      ");
l5=new Label(" ");
ch1=new Choice();
ch1.addItem("BCA");
ch1.addItem("BBA");
ch1.addItem("BTech");
ch1.addItem("MBA");
ch1.addItem("MCA");
ch2=new Choice();
for(int i=1;i<=8;i++)
ch2.addItem(String.valueOf(i));
t1=new TextField(15);
t2=new TextField(15);
t3=new TextField(15);
t4=new TextField(15);
//b1=new Button("Save");
//b2=new Button("delete");
//b3=new Button("cancle");
b4=new Button("clear");
b5=new Button("select");
setLayout(new FlowLayout());
setBackground(Color.yellow);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(ch1);
add(l4);
add(ch2);
add(b1);
//add(b2);
//add(b3);
//add(b4);
add(l5);
add(b5);
//b1.addActionListener(this);
//sb2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
ch1.addItemListener(this);
ch2.addItemListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b3)
{
l5.setText("You have Pressed Cancled Button");

}
else if(ae.getSource()==b4)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
}
else if(ae.getSource()==b5)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException cnfe)
{
System.out.println("Error is "+cnfe.getMessage());
}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:Info");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from table1 where course='"+cnm+"'");
while(res.next())
{
t2.setText(res.getString(2));
}
}
catch(SQLException se)
{
System.out.println("Error in database :: " +se.getMessage());
}
}
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==ch1)
{
cnm=String.valueOf(ie.getItem());
}
if(ie.getSource()==ch2)
{
sem=Integer.parseInt(String.valueOf(ie.getItem()));
}
}
public static void main(String a[])
{
Select1 as=new Select1();
as.setSize(300,200);
as.setVisible(true);
as.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
}
}

No comments:

Post a Comment