My button is not gaving out any action when clicked:
(libraryBtn):
package LibraryDatabase;
import static javax.swing.JOptionPane.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class PostLibraryDatabase extends JFrame implements ActionListener {
// Text Fields XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
JTextField firstName, surName, id, serialNumber, category, dateToday, coverTitle, isbnNumber,
authoursName, coAuthoursName, pubDate, loanDate, returnedDate, email, details;
// JButton Fields XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
JButton writeBtn, displayBtn, exitBtn, libraryBtn, resetBtn ;
// ImageIcon Fields XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ImageIcon pic = new ImageIcon ("Postlib.png");
JButton picBtn = new JButton ("" ,pic);
// TextArea Fields XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
TextArea information = new TextArea(18, 97);
DBHandler db = new DBHandler();
public static void main(String[] args) {
new PostLibraryDatabase();
}
public PostLibraryDatabase() {
setLayout(new BorderLayout());
// text Field
firstName = new JTextField(16);
surName = new JTextField(17);
id = new JTextField(10);
serialNumber = new JTextField(18);
category = new JTextField(21);
dateToday = new JTextField(8);
coverTitle = new JTextField(25);
isbnNumber = new JTextField(30);
authoursName = new JTextField(16);
coAuthoursName = new JTextField(17);
pubDate = new JTextField(8);
loanDate = new JTextField(8);
returnedDate = new JTextField(8);
email = new JTextField(27);
details = new JTextField(48);
writeBtn = new JButton("Write to database");
displayBtn = new JButton("Display Records");
libraryBtn = new JButton("Library Record");
resetBtn = new JButton("Reset");
exitBtn = new JButton("Exit");
// position top XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
JPanel top = new JPanel();
add("North", top);
// position center XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
JPanel middle = new JPanel();
middle.add(new JLabel("First name:"));
middle.add(firstName);
middle.add(new JLabel("Surname:"));
middle.add(surName);
middle.add(new JLabel("Library ID:"));
middle.add(id);
middle.add(new JLabel("Category name:"));
middle.add(category);
middle.add(new JLabel("Cover Title:"));
middle.add(coverTitle);
middle.add(new JLabel("Today's Date:"));
middle.add(dateToday);
middle.add(new JLabel(" ISBN Number:"));
middle.add(isbnNumber);
middle.add(new JLabel("Authours Name(s):"));
middle.add(authoursName);
middle.add(new JLabel(" Co - Authours Name(s):"));
middle.add(coAuthoursName);
middle.add(new JLabel("Serial Number:"));
middle.add(serialNumber);
middle.add(new JLabel(" Dated Published :"));
middle.add(pubDate);
middle.add(new JLabel(" Loan Date:"));
middle.add(loanDate);
middle.add(new JLabel("Returned Date:"));
middle.add(returnedDate);
middle.add(new JLabel(" Borrowers E-mail Address:"));
middle.add(email);
middle.add(new JLabel("Book / Magazine Details:"));
middle.add(details);
information.setText(LibraryData.listAll());
middle.add(information);
add("Center", middle);
// position center
JPanel bottom = new JPanel();
bottom.add(writeBtn);
bottom.add(displayBtn);
bottom.add(libraryBtn);
bottom.add(resetBtn);
bottom.add(exitBtn);
add("South", bottom);
add("West", new JPanel());
add("East", new JPanel());
// ActionListener XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
writeBtn.addActionListener(this);
displayBtn.addActionListener(this);
libraryBtn.addActionListener(this);
resetBtn.addActionListener(this);
exitBtn.addActionListener(this);
// Windows Size XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
setSize(730, 690);
top.add (picBtn);
setTitle("Post Library Database");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
}
// Action Performed XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
public void actionPerformed(ActionEvent e) {
if (e.getSource() == writeBtn) {
String f = firstName.getText();
String s = surName.getText();
String z = id.getText();
String a = serialNumber.getText();
String b = category.getText();
String c = dateToday.getText();
String d = coverTitle.getText();
String g = isbnNumber.getText();
String h = authoursName.getText();
String i = coAuthoursName.getText();
String k = pubDate.getText();
String l = loanDate.getText();
String m = returnedDate.getText();
String n = email.getText();
String o = details.getText();
// XXXXXX if any field is blank, signal an error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if (f.equals("") || s.equals("") || i.equals("")) {
showMessageDialog(this, "One or more fields blank");
return;
}
boolean ok = db.write(z, s, f, a, b, c, d, g, h, i, k, l, m, n, o);
id.setText("");
if (!ok) showMessageDialog(this, "Duplicate key " + id);
else {
firstName.setText("");
surName.setText("");
serialNumber.setText("");
category.setText("");
dateToday.setText("");
coverTitle.setText("");
authoursName.setText("");
coAuthoursName.setText("");
pubDate.setText("");
loanDate.setText("");
returnedDate.setText("");
email.setText("");
details.setText("");
}
if (e.getSource() == libraryBtn) {
new CheckLin();
} else if (e.getSource() == exitBtn) {
LibraryData.close();
System.exit(0);
}
}
}
}