chris88
07-15-2009, 08:21 PM
how to convert this java program into applet so that it can be show in a website
thx
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
public class Searchplayer implements ActionListener{
JFrame f;
JLabel lid,lname,lcountry,lphone;
TextField tid,tname,tcountry,tphone;
JButton b1,b2;
JPanel p1,p2,p3,p4;
Connection c;
Statement s;
ResultSet rs;
public Searchplayer(){
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
f=new JFrame("Player details");
lid=new JLabel("Player ID");
lname=new JLabel("Player name");
lcountry=new JLabel("Country");
lphone=new JLabel("Phone");
tid=new TextField(10);
tname=new TextField(15);
tcountry=new TextField(10);
tphone=new TextField(10);
b1=new JButton("SEARCH");
b1.addActionListener(this);
b2=new JButton("EXIT");
b2.addActionListener(this);
f.setLayout(new GridLayout(3,2));
f.setVisible(true);
f.setSize(300,300);
p1.add(lid);
p1.add(tid);
p1.add(b1);
f.add(p1);
p2.add(lname);
p2.add(tname);
f.add(p2);
p3.add(lcountry);
p3.add(tcountry);
f.add(p3);
p4.add(lphone);
p4.add(tphone);
f.add(p4);
tname.setEnabled(false);
tcountry.setEnabled(false);
tphone.setEnabled(false);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){System.exit(0);}});
}
public void actionPerformed (ActionEvent e){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1){
System.err.println(e1.getMessage());
}
try{
c=DriverManager.getConnection("Jdbc:Odbc:db1","","");
s=c.createStatement();
rs=s.executeQuery("select * from detailsofplayers where ID='"+tid.getText()+"'");
if (rs.next()){
tname.setText(rs.getString(2));
tcountry.setText(rs.getString(3));
tphone.setText(rs.getString(4));
}
else{
tname.setText("");
tcountry.setText("");
tphone.setText("");
JOptionPane.showMessageDialog(null,"Players record not found");
}
}
catch(SQLException e2){
System.err.println(e2.getMessage());
}
}
public static void main(String args []){
Searchplayer s=new Searchplayer();
}
}
thx
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
public class Searchplayer implements ActionListener{
JFrame f;
JLabel lid,lname,lcountry,lphone;
TextField tid,tname,tcountry,tphone;
JButton b1,b2;
JPanel p1,p2,p3,p4;
Connection c;
Statement s;
ResultSet rs;
public Searchplayer(){
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
f=new JFrame("Player details");
lid=new JLabel("Player ID");
lname=new JLabel("Player name");
lcountry=new JLabel("Country");
lphone=new JLabel("Phone");
tid=new TextField(10);
tname=new TextField(15);
tcountry=new TextField(10);
tphone=new TextField(10);
b1=new JButton("SEARCH");
b1.addActionListener(this);
b2=new JButton("EXIT");
b2.addActionListener(this);
f.setLayout(new GridLayout(3,2));
f.setVisible(true);
f.setSize(300,300);
p1.add(lid);
p1.add(tid);
p1.add(b1);
f.add(p1);
p2.add(lname);
p2.add(tname);
f.add(p2);
p3.add(lcountry);
p3.add(tcountry);
f.add(p3);
p4.add(lphone);
p4.add(tphone);
f.add(p4);
tname.setEnabled(false);
tcountry.setEnabled(false);
tphone.setEnabled(false);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){System.exit(0);}});
}
public void actionPerformed (ActionEvent e){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1){
System.err.println(e1.getMessage());
}
try{
c=DriverManager.getConnection("Jdbc:Odbc:db1","","");
s=c.createStatement();
rs=s.executeQuery("select * from detailsofplayers where ID='"+tid.getText()+"'");
if (rs.next()){
tname.setText(rs.getString(2));
tcountry.setText(rs.getString(3));
tphone.setText(rs.getString(4));
}
else{
tname.setText("");
tcountry.setText("");
tphone.setText("");
JOptionPane.showMessageDialog(null,"Players record not found");
}
}
catch(SQLException e2){
System.err.println(e2.getMessage());
}
}
public static void main(String args []){
Searchplayer s=new Searchplayer();
}
}