public class EventView extends javax.swing.JFrame {
Connection conn = JavaConnect.ConnectDB();
PreparedStatement pst = null;
ResultSet rs = null;
private EventModel model;
/** Constructor */
public EventView(EventModel model) {
initComponents();
this.model = model;
updateEventTable();
}
public void addEventListener(ActionListener al) {
addEventButton.addActionListener(al);
}
/* public void clearListener(ActionListener cl) {
clearEventButton.addActionListener(cl);
}*/
public void addDialogListener(ActionListener ae) {
addEvent.addActionListener(ae);
}
public void editDialogListener(ActionListener ee) {
editEvent.addActionListener(ee);
}
public String getEventName() {
return txtName.getText();
}
public Date eventDate() {
return txtDate.getDate();
}
public String startTime() {
return txtStart.getText();
}
public String endTime() {
return txtEnd.getText();
}
public String locationWhere() {
return txtWhere.getText();
}
public String getDetails() {
return txtDetails.getText();
}
public String getOpportunities() {
return txtOppor.getText();
}
public String getMore() {
return txtMore.getText();
}
public void showError(Exception e) {
JOptionPane.showMessageDialog(null, e);
}
public void showSuccess(String e) {
JOptionPane.showMessageDialog(null, e);
}
public void updateEventTable() {
try {
String sql = "SELECT date as 'Date',eventName as 'Name', time as 'Start Time' FROM Event";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
tableEvent.setModel(DbUtils.resultSetToTableModel(rs));
tableEvent.getColumnModel().getColumn(0).setPreferredWidth(80);
tableEvent.getColumnModel().getColumn(1).setPreferredWidth(170);
tableEvent.getColumnModel().getColumn(2).setPreferredWidth(110);
}
catch (Exception e ) {
JOptionPane.showMessageDialog(null, e);
} finally {
try {
rs.close(); pst.close();conn.close();;
} catch(SQLException e){}
}
}
public static void main(String args[]) {
public void run() {
EventModel model = new EventModel();
new EventView(model).setVisible(true);
}
});
}
public class EventController {
//... The Controller needs to interact with both the Model and View.
private EventModel model;
private EventView view;
/** Constructor */
public EventController(EventModel model, EventView view){
this.model = model;
this.view = view;
//... Add listeners to the view.
view.addEventListener(new addEventListener());
view.addDialogListener(new addDialogListener());
view.editDialogListener(new editDialogListener());
}
private class addEventListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
String name = "";
String date;
String start="";
String end="";
String venue="";
String details="";
String opportunities="";
String moreOppor="";
try {
name = view.getEventName();
date = view.eventDate().toString();
start = view.startTime();
end = view.endTime();
venue = view.locationWhere();
details = view.getDetails();
opportunities = view.getOpportunities();
moreOppor = view.getMore();
model.addEvent(name,date,start,venue,details,opportunities,moreOppor,end);
view.showSuccess("Event Added!");
} catch (Exception ex) {
view.showError(ex);
}
}
}
private class addDialogListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("1");
}
}
private class editDialogListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("2");
}
}
} // end class
I am unable to execute the events of the components being clicked. why is this? what have i done wrong