button listener not working
hi guys!! trying to get this button listener appended to SUBMIT button working. but the button is just dead. can anyone tell me where im going wrong please?
Code:
/**
* Title: project
* Description:
* Copyright: Copyright (c) 2005
* Company: college practicals
* @author trish
* @version 1.0
*/
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
import javax.swing.*;
public class project extends Applet
{
private Connection dbConn;
Label label1;
Button buttonEnterDetails;
Button buttonUpdateDetails;
Button buttonContactAdmin;
Button buttonSearchForBook;
Button buttonSubmit;
TextField textField1;
TextField textField2;
TextField textField3;
TextField textPhone;
TextField textEmail;
TextField textBookTitle;
TextField textAuthor;
TextField textBookType;
TextField textPublisher;
TextField textEdition;
Label labelName;
Label labelAddress1;
Label LabelAddress2;
Label labelAddress3;
Label labelPhone;
Label labelEmail;
Label labelBookTitle;
Label labelAuthor;
Label labelEdition;
Label labelBookType;
Label labelPublisher;
Button button1 = new Button();
public Connection getDBConnection()
{
Connection con;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String str2 ="jdbc:odbc:details";
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
// Make a connection to the my Oracle Database
con = DriverManager.getConnection(str2, "", "");
}
catch (Exception e)
{
//JOptionPane.showMessageDialog(null, "Wrong twat");
con = null;
}
return con;
}
public void init()
{
setLayout(null);
setBackground(Color.white);
setSize(800, 800); //size of applet in web page
label1 = new Label("Welcome to Books & Buy", Label.CENTER);
label1.setFont(new Font("Serif", Font.BOLD, 20));
label1.setBounds(70,8,280,40);
label1.setBackground(Color.white);
label1.setForeground(Color.blue);
add(label1); // add label1 to web page
buttonEnterDetails = new Button();
buttonEnterDetails.setLabel("Enter Details");
buttonEnterDetails.setBounds(8,152,86,32);
buttonEnterDetails.setBackground(Color.white);
buttonEnterDetails.setForeground(Color.blue);
add(buttonEnterDetails);
buttonUpdateDetails = new Button();
buttonUpdateDetails.setLabel("Update Details");
buttonUpdateDetails.setBounds(104,152,86,32);
buttonUpdateDetails.setBackground(Color.white);
buttonUpdateDetails.setForeground(Color.blue);
add(buttonUpdateDetails);
buttonContactAdmin = new Button();
buttonContactAdmin.setLabel("ContactAdmin");
buttonContactAdmin.setBounds(200,152,86,32);
buttonContactAdmin.setBackground(Color.white);
buttonContactAdmin.setForeground(Color.blue);
add(buttonContactAdmin);
buttonSearchForBook = new Button();
buttonSearchForBook.setLabel("Search");
buttonSearchForBook.setBounds(300,152,86,32);
buttonSearchForBook.setBackground(Color.white);
buttonSearchForBook.setForeground(Color.blue);
add(buttonSearchForBook);
buttonSubmit = new Button();
buttonSubmit.setLabel("Submit");
buttonSubmit.setBounds(400,750,86,32);
buttonSubmit.setBackground(Color.white);
buttonSubmit.setForeground(Color.blue);
add(buttonSubmit);
ButtonListener ourButtonListener = new ButtonListener();
buttonEnterDetails.addActionListener(ourButtonListener);
buttonUpdateDetails.addActionListener(ourButtonListener);
buttonContactAdmin.addActionListener(ourButtonListener);
buttonSearchForBook.addActionListener(ourButtonListener);
buttonSubmit.addActionListener(ourButtonListener);
}
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Object press = event.getSource();
if(press == buttonEnterDetails)
{
buttonContactAdmin.setVisible(false);
buttonEnterDetails.setVisible(false);
buttonUpdateDetails.setVisible(false);
buttonSearchForBook.setVisible(false);
Label labelName = new Label("Name:");
labelName.setFont(new Font("Serif", Font.BOLD, 14));
labelName.setBounds(8,60,50,40);
labelName.setBackground(Color.white);
labelName.setForeground(Color.blue);
add(labelName);
textField1 = new TextField();
textField1.setBounds(100,60,250,30);
add(textField1);
Label labelAddress1 = new Label("Address1:");
labelAddress1.setFont(new Font("Serif", Font.BOLD, 14));
labelAddress1.setBounds(8,120,75,40);
labelAddress1.setBackground(Color.white);
labelAddress1.setForeground(Color.blue);
add(labelAddress1);
textField2 = new TextField();
textField2.setVisible(true);
textField2.setBounds(100,120,250,30);
add(textField2);
Label labelAddress2 = new Label("Address2:");
labelAddress2.setFont(new Font("Serif", Font.BOLD, 14));
labelAddress2.setBounds(8,180,75,40);
labelAddress2.setBackground(Color.white);
labelAddress2.setForeground(Color.blue);
add(labelAddress2);
textField3 = new TextField();
textField3.setBounds(100,180,250,30);
add(textField3);
Label labelAddress3 = new Label("Address3:");
labelAddress3.setFont(new Font("Serif", Font.BOLD, 14));
labelAddress3.setBounds(8,240,75,40);
labelAddress3.setBackground(Color.white);
labelAddress3.setForeground(Color.blue);
add(labelAddress3);
textField3 = new TextField();
textField3.setBounds(100,240,250,30);
add(textField3);
Label labelPhone = new Label("PhoneNo:");
labelPhone.setFont(new Font("Serif", Font.BOLD, 14));
labelPhone.setBounds(8,300,75,40);
labelPhone.setBackground(Color.white);
labelPhone.setForeground(Color.blue);
add(labelPhone);
textPhone = new TextField();
textPhone.setBounds(150,300,310,30);
add(textPhone);
Choice choice = new Choice();
choice.setBounds(100,300,50,60);
choice.addItem("085");
choice.addItem("086");
choice.addItem("087");
add(choice);
Label labelEmail = new Label("Email:");
labelEmail.setFont(new Font("Serif", Font.BOLD, 14));
labelEmail.setBounds(8,360,75,40);
labelEmail.setBackground(Color.white);
labelEmail.setForeground(Color.blue);
add(labelEmail);
textEmail = new TextField();
textEmail.setBounds(100,360,310,30);
add(textEmail);
Label labelBookTitle = new Label("Book Title:");
labelBookTitle.setFont(new Font("Serif", Font.BOLD, 14));
labelBookTitle.setBounds(8,420,75,40);
labelBookTitle.setBackground(Color.white);
labelBookTitle.setForeground(Color.blue);
add(labelBookTitle);
textBookTitle = new TextField();
textBookTitle.setBounds(100,420,310,30);
add(textBookTitle);
Label labelAuthor = new Label("Author:");
labelAuthor.setFont(new Font("Serif", Font.BOLD, 14));
labelAuthor.setBounds(8,480,75,40);
labelAuthor.setBackground(Color.white);
labelAuthor.setForeground(Color.blue);
add(labelAuthor);
textAuthor = new TextField();
textAuthor.setBounds(100,480,310,30);
add(textAuthor);
Label labelBookType = new Label("Book Type:");
labelBookType.setFont(new Font("Serif", Font.BOLD, 14));
labelBookType.setBounds(8,540,75,40);
labelBookType.setBackground(Color.white);
labelBookType.setForeground(Color.blue);
add(labelBookType);
textBookType = new TextField();
textBookType.setBounds(100,540,310,30);
add(textBookType);
Label labelPublisher = new Label("Publisher:");
labelPublisher.setFont(new Font("Serif", Font.BOLD, 14));
labelPublisher.setBounds(8,600,75,40);
labelPublisher.setBackground(Color.white);
labelPublisher.setForeground(Color.blue);
add(labelPublisher);
textPublisher = new TextField();
textPublisher.setBounds(100,600,310,30);
add(textPublisher);
Label labelEdition = new Label("Edition:");
labelEdition.setFont(new Font("Serif", Font.BOLD, 14));
labelEdition.setBounds(8,660,75,40);
labelEdition.setBackground(Color.white);
labelEdition.setForeground(Color.blue);
add(labelEdition);
textEdition = new TextField();
textEdition.setBounds(100,660, 200, 30);
add(textEdition);
}
else
if(press == buttonSubmit)
{
//System.exit(0);
dbConn = getDBConnection();
try {
Statement s = dbConn.createStatement();
s.execute("insert into details values" + "textField1, s.getText()textBookTitle) + s.getText()textAuthor))");
}
catch (Exception err) {
System.out.println("ERROR: " + err);
}
} // end of if
else
if(press == buttonUpdateDetails)
{
buttonContactAdmin.setVisible(false);
buttonEnterDetails.setVisible(false);
buttonUpdateDetails.setVisible(false);
buttonSearchForBook.setVisible(false);
}
else
if(press ==buttonContactAdmin)
{
buttonContactAdmin.setVisible(false);
buttonEnterDetails.setVisible(false);
buttonUpdateDetails.setVisible(false);
buttonSearchForBook.setVisible(false);
}
}
}
}