[b]Hi
Every1
I have coded a applet program named Friends.java, long years ago (may be 5 years) and i made it out without any exceptions and i save the file in a CD. But now when i execute the program i don't get any Exceptions but when i execute appletviewer command i'm getting error message as:- "I/O Exception while reading: F:\Friends.html (The system cannot find the specified file)
The following is the file, some1 please execute the following program on their respective JVM's and let me know please
//import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//import java.util.*;
//import java.sql.*;
public class Friends extends JFrame implements ActionListener,MouseListener
{
JFrame frame;
JPanel main,card,p1,p2;
static PreparedStatement stat,stat1,stat2;
static Connection con,conn,connn;
static ResultSet result;
JOptionPane pobj;
JLabel l,l1,l2,l3,l4,l5,l6,l7;
TextField t,t1,t2,t3,t6,t7;
TextArea ta;
Choice cities;
JButton enter,add,del,query,update,exit,truncate;
FlowLayout fl;
CardLayout cl;
GridBagLayout gbl,gbl2,gbl3;
GridBagConstraints gbc,gbc2,gbc3;
Thread th;
//Date date;
GregorianCalendar calendar;
String strDate,strTime,strStatus;
public Friends()
{
frame=new JFrame(" Friends Contact Numbers and their Birthday Dates ");
frame.setSize(500,500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
main=new JPanel();
card=new JPanel();
frame.getContentPane().add(main);
gbc=new GridBagConstraints();
gbc2=new GridBagConstraints();
gbc3=new GridBagConstraints();
gbl=new GridBagLayout();
gbl2=new GridBagLayout();
gbl3=new GridBagLayout();
cl=new CardLayout();
main.setLayout(gbl);
card.setLayout(cl);
gbc.anchor=GridBagConstraints.CENTER;
gbc.gridx=1;
gbc.gridy=2;
gbl.setConstraints(card,gbc);
main.add(card);
main.setBackground(Color.pink);
Font font =new Font("Times New Roman" ,Font.BOLD,12);
JOptionPane pobj=new JOptionPane();
l=new JLabel("Enter Access Code");
l.setForeground(Color.blue);
t=new TextField(10);
t.setEchoChar('*');
l1=new JLabel("Friend Name");
l2=new JLabel("Cell Number");
l3=new JLabel("LandLine");
l4=new JLabel("Address");
l5=new JLabel("City");
cities=new Choice();
//cities.setBackground(Color.yellow);
cities.setFont(font);
cities.addItem("----------Select----------");
cities.addItem("Hyderabad");
cities.addItem("Bangalore");
cities.addItem("Guntakal");
cities.addItem("Chattisgard");
t1=new TextField(17);
t1.setFont(font);
t1.setForeground(Color.blue);
//t1.setBackground(Color.yellow);
t2=new TextField(17);
t2.setFont(font);
//t2.setBackground(Color.yellow);
t3=new TextField(17);
t3.setFont(font);
t3.setForeground(Color.blue);
//t3.setBackground(Color.yellow);
ta=new TextArea(3,17);
ta.setFont(font);
ta.setForeground(Color.blue);
//ta.setBackground(Color.yellow);
l6=new JLabel("E - mail ");
t6=new TextField(17);
t6.setFont(font);
//t6.setBackground(Color.yellow);
l7=new JLabel("Birthday");
t7=new TextField(17);
t7.setFont(font);
//t7.setBackground(Color.yellow);
add=new JButton("Insert");
del=new JButton("Delete");
query =new JButton ("Query");
update=new JButton("Update");
exit=new JButton("Exit");
enter=new JButton("Enter");
truncate=new JButton("Truncate");
p1=new JPanel();
p1.setLayout(gbl2);
p1.setBackground(Color.cyan);
gbc2.anchor=GridBagConstraints.CENTER;
gbc2.gridx=1;
gbc2.gridy=1;
gbl2.setConstraints(l,gbc2);
p1.add(l);
gbc2.anchor=GridBagConstraints.CENTER;
gbc2.gridx=2;
gbc2.gridy=1;
gbl2.setConstraints(t,gbc2);
p1.add(t);
gbc2.anchor=GridBagConstraints.CENTER;
gbc2.gridx=2;
gbc2.gridy=2;
gbl2.setConstraints(enter,gbc2);
p1.add(enter);
enter.addActionListener(this);
//enter.addMouseListener(this);
enter.setToolTipText("Enter the required code in the Text Box and Click this button to go to the next page");
p2=new JPanel();
p2.setLayout(gbl3);
p2.setBackground(Color.cyan);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=5;
gbc3.gridy=1;
gbl3.setConstraints(truncate,gbc3);
p2.add(truncate);
truncate.setFont(font);
truncate.setToolTipText("Click this button to Truncate the data in the Database");
truncate.addActionListener(this);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=1;
gbc3.gridy=1;
gbl3.setConstraints(l1,gbc3);
p2.add(l1);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=2;
gbc3.gridy=1;
gbl3.setConstraints(t1,gbc3);
p2.add(t1);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=1;
gbc3.gridy=2;
gbl3.setConstraints(l2,gbc3);
p2.add(l2);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=2;
gbc3.gridy=2;
gbl3.setConstraints(t2,gbc3);
p2.add(t2);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=1;
gbc3.gridy=3;
gbl3.setConstraints(l3,gbc3);
p2.add(l3);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=2;
gbc3.gridy=3;
gbl3.setConstraints(t3,gbc3);
p2.add(t3);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=1;
gbc3.gridy=4;
gbl3.setConstraints(l4,gbc3);
p2.add(l4);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=2;
gbc3.gridy=4;
gbl3.setConstraints(ta,gbc3);
p2.add(ta);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=1;
gbc3.gridy=5;
gbl3.setConstraints(l5,gbc3);
p2.add(l5);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=2;
gbc3.gridy=5;
gbl3.setConstraints(cities,gbc3);
p2.add(cities);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=1;
gbc3.gridy=6;
gbl3.setConstraints(l6,gbc3);
p2.add(l6);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=2;
gbc3.gridy=6;
gbl3.setConstraints(t6,gbc3);
p2.add(t6);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=1;
gbc3.gridy=7;
gbl3.setConstraints(l7,gbc3);
p2.add(l7);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=2;
gbc3.gridy=7;
gbl3.setConstraints(t7,gbc3);
p2.add(t7);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=1;
gbc3.gridy=8;
gbl3.setConstraints(add,gbc3);
p2.add(add);
add.setFont(font);
add.setToolTipText("Click this button to Add the details you have entered to the Database");
add.addActionListener(this);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=2;
gbc3.gridy=8;
gbl3.setConstraints(del,gbc3);
p2.add(del);
del.setFont(font);
del.setToolTipText("Click this button to Delete the details you have entered to the Database");
del.addActionListener(this);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=3;
gbc3.gridy=8;
gbl3.setConstraints(query,gbc3);
p2.add(query);
query.setFont(font);
query.setToolTipText("Click this button to View the details of your Friends that you have entered in the Database");
query.addActionListener(this);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=4;
gbc3.gridy=8;
gbl3.setConstraints(update,gbc3);
p2.add(update);
update.setFont(font);
update.setToolTipText("Click this button to Update the details of your Friends that you have entered in the Database");
update.addActionListener(this);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=5;
gbc3.gridy=8;
gbl3.setConstraints(exit,gbc3);
p2.add(exit);
exit.setFont(font);
exit.setToolTipText("Click this button to Exit ");
exit.addActionListener(this);
//th=new Thread(this);
//th.start();
card.add(p1,"Panel1");
card.add(p2,"Panel2");
}
public void mousePressed(MouseEvent me)
{
cl.next(card);
}
public void mouseClicked(MouseEvent me)
{ }
public void mouseEntered(MouseEvent me)
{ }
public void mouseExited(MouseEvent me)
{ }
public void mouseReleased(MouseEvent me)
{ }
public static void main(String args[])
{
Friends friends=new Friends();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Friends ","sa","jyotshna");
stat1=con.prepareStatement("Select * from Friends where Name = ?");
}
catch(Exception e)
{
System.out.println("Could not execute the query " + e);
}
}
/*public void run()
{
while(th!=null)
{
disp();
try
{
th.sleep(1000);
}
catch(InterruptedException e)
{
getAppletContext().showStatus("Thread Interrupted");
}
}
}
public void disp()
{
date=new Date();
calendar=new GregorianCalendar();
calendar.setTime(date);
strTime=calendar.get(Calendar.HOUR)+ ":" +(calendar.get(Calendar.MINUTE)) +":"+(calendar.get(Calendar.SECOND));
strDate=(calendar.get(Calendar.MONTH)+1)+ ":" +calendar.get(Calendar.DATE)+":"+calendar.get(Cale ndar.YEAR);
strStatus=strTime+ " " +strDate;
getAppletContext().showStatus(strStatus);
}*/
public void actionPerformed(ActionEvent ae)
{
Object obj=ae.getSource();
if(obj==enter)
{
String code;
code=t.getText();
if(obj==enter)
if(code.length()==0)
{
JOptionPane.showMessageDialog(frame ," Please . . .\n"+
"Enter the Access Code");
}
else if(code.equals("Jyotshna"))
{
t.setText("");
cl.show(card,"Panel2");
}
else if(code.length() > 8 )
{
JOptionPane.showMessageDialog(frame ,"Access Code cannot exceed more than 8 digits . . . ");
}
else
{
JOptionPane.showMessageDialog(frame ," Sorry . . . \n" +
" Invalid Access Code");
return;
}
}
Object source=ae.getSource();
if(source==add)
{
String name,cell,landline,textarea,email,birthday;
name=t1.getText();
cell=t2.getText();
landline=t3.getText();
textarea=ta.getText();
email=t6.getText();
birthday=t7.getText();
if(name.length()==0)
{
pobj.showMessageDialog(frame,("Friends Name cannot be left blank") , "ErrorMessage",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Friends Name cannot be left blank");
return;
}
if(cell.length()==0)
{
pobj.showMessageDialog(frame,("Cell number is must . It cannot be left blank") , "ErrorMessage",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Gender is must . It cannot be left blank");
return;
}
/*if(landline.length()==0)
{
pobj.showMessageDialog(frame,("LandLine number is must . It cannot be left blank") , "ErrorMessage",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Gender is must . It cannot be left blank");
return;
}
if(textarea.length()==0)
{
pobj.showMessageDialog(frame,("Address is must . It cannot be left blank") , "ErrorMessage",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Gender is must . It cannot be left blank");
return;
}
if(email.length()==0)
{
pobj.showMessageDialog(frame,("E - mail address is must . It cannot be left blank") , "ErrorMessage",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Gender is must . It cannot be left blank");
return;
}*/
try
{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Friends ","sa","jyotshna");
stat=con.prepareStatement("Insert into Friends(Name,Cell,LandLine,Address,City,E_mail,Bir thday) values(?, ?, ?, ?, ?, ?, ?)");
stat.setString(1,t1.getText());
stat.setString(2,t2.getText());
stat.setString(3,t3.getText());
stat.setString(4,ta.getText());
stat.setString(5,(String)cities.getSelectedItem()) ;
stat.setString(6,t6.getText());
stat.setString(7,t7.getText());
stat.executeUpdate();
pobj.showMessageDialog(frame,(" Congratulations ! ! ! \n" +
"Your Details have been added to the Database") , "Successfull Message",JOptionPane.INFORMATION_MESSAGE);
//JOptionPane.showMessageDialog(frame,new String ("Congratulations ! ! ! Your Details have been Accepted"));
t1.setText("");
t2.setText("");
t3.setText("");
ta.setText("");
//cities.setText("-----Select----");
t6.setText("");
t7.setText("");
}
catch(Exception exception)
{
pobj.showMessageDialog(frame,(" Sorry . . . \n" +
"Record has not been Added to the Database" ) , "Error Message",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,new String("Error occured while entering Data into the Database" +exception));
}
}
if(source == del)
{
String name;
name=t1.getText();
if(name.length()==0)
{
pobj.showMessageDialog(frame,("Friends Name cannot be left blank") , "Error Message",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Friends Name cannot be left blank");
return;
}
try
{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Friends ","sa","jyotshna");
stat=con.prepareStatement("Delete Friends where Name = ? ");
stat.setString(1,t1.getText());
stat.executeUpdate();
pobj.showMessageDialog(frame,("The Details that you have entered have been Deleted in the Database") , "Information Message",JOptionPane.INFORMATION_MESSAGE);
//JOptionPane.showMessageDialog(frame,new String("The Details that you have entered have been Deleted in the Database"));
t1.setText("");
t2.setText("");
t3.setText("");
ta.setText("");
t6.setText("");
t7.setText("");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(frame,new String("Error occured while deleting the Data from the Database" +e));
}
}
if(source == update)
{
String name;
name=t1.getText();
if(name.length()==0)
{
pobj.showMessageDialog(frame,("Friends Name cannot be left blank") , "Error Message",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Friends Name cannot be left blank");
return;
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Friends ","sa","jyotshna");
//stat=con.prepareStatement("Update Friends set(Name=?,Cell=?,LandLine=?,Address=?,City=?,E_ma il=?,Birthday=? where Name=?)");
stat=con.prepareStatement( "Update Friends set Cell=? LandLine=? Address=? City=? E_mail=? Birthday=? where Name=?");
stat.setString(1,t1.getText());
stat.setString(2,t2.getText());
stat.setString(3,t3.getText());
stat.setString(4,ta.getText());
stat.setString(5,(String)cities.getSelectedItem()) ;
stat.setString(6,t6.getText());
stat.setString(7,t7.getText());
stat.executeUpdate();
pobj.showMessageDialog(frame,("UPDATED ") , "Information Message",JOptionPane.INFORMATION_MESSAGE);
//JOptionPane.showMessageDialog(frame,new String("The details that you have entered have been deleted in the database successfully"));
}
catch(Exception e)
{
JOptionPane.showMessageDialog(frame,new String(""+e));
//JOptionPane.showMessageDialog(frame,new String(" Sorry !" +e));
}
}
if(source==exit)
{
System.exit(0);
}
if(source==query)
{
try
{
String name,gender;
name=t1.getText();
if(name.length()==0)
{
JOptionPane.showMessageDialog(frame,"Friends Name cannot be left blank");
return;
}
stat1.setString(1,t1.getText());
result=stat1.executeQuery();
result.next();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(frame,"Could not execute the Query"+e );
}
showRecord(result);
}
}
public void showRecord(ResultSet result)
{
try
{
t1.setText(result.getString(1));
t2.setText(result.getString(2));
t3.setText(result.getString(3));
ta.setText(result.getString(4));
//cities.setText(result.getString(5));
t6.setText(result.getString(6));
t7.setText(result.getString(7));
}
catch(Exception e)
{
JOptionPane.showMessageDialog(frame," Sorry . . . \n" +
"The ' NAME ' you entered does not exists in the Database");
//JOptionPane.showMessageDialog(frame,"The NAME you entered does not exists in the Database "+ e);
}
}
}