This is my JPanels class for a small program I am working on. The program launches and displays my GUI correctly. Issue is for some reason my actionEvent isnt firing onClick.
I put in a println in the actionPerformed to see if it was actually launching the event and found it wasn't. Could any of you guys help me figure out where I'm going wrong here?
This is the class in question.
package MetaMarket.GUI;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.text.NumberFormatter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import static MetaMarket.GUI.Fields.*;
public class UserInput {
private final JPanel userInput;
private final JPanel displayInput;
public UserInput(){
//set up panel
this.userInput = new JPanel();
userInput.setLayout(null);
userInput.setBounds(16,16,300,500);
userInput.setBorder(new TitledBorder("Shift Report"));
userInput.add(Labels.getUserJLabel());
//set up select user combo box
userInput.add(getUserSelection());
// set up callsReceivedJLabel
userInput.add(Labels.getCallsReceivedJLabel());
// set up callsReceivedJTextField
userInput.add(Fields.getCallsReceivedJTextField());
// set up ticketsOpenedJLabel
userInput.add(Labels.getTicketsOpenedJLabel());
// set up ticketsOpenedJTextField
userInput.add(getTicketsOpenedJTextField());
// set up ticketsClosedJLabel
userInput.add(Labels.getTicketsClosedJLabel());
// set up ticketsClosedJTextField
userInput.add(getTicketsClosedJTextField());
// set up vpnRequestJLabel
userInput.add(Labels.getVpnRequestsJLabel());
// set up vpnRequestJTextField
userInput.add(getVpnRequestsJTextField());
// set up notesJLabel
userInput.add(Labels.getNotesJLabel());
// set up notesJTextArea
userInput.add(Fields.getNotesJTextArea());
Object[] row = new Object[8];
JTable table = new JTable();
Object[] columns = {"Date", "Representative","Calls","Tickets Opened", "Tickets Closed", "VPN Requests", "FCR"
,"Comments"};
JTableHeader header = table.getTableHeader();
header.setBackground(Color.PINK);
DefaultTableModel model = new DefaultTableModel();
model.setColumnIdentifiers(columns);
table.setModel(model);
Buttons.createLogButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("action is beginning");
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
int openInt = Integer.parseInt(getTicketsOpenedJTextField().getText());
int closeInt = Integer.parseInt(getTicketsClosedJTextField().getText());
int vpn = Integer.parseInt(getVpnRequestsJTextField().getText());
double trueClose = closeInt - vpn;
double trueOpen = openInt - vpn;
double fcr = trueClose/trueOpen;
NumberFormat defaultFormat = NumberFormat.getPercentInstance();
defaultFormat.setMinimumFractionDigits(2);
row[0] = date;
row[1] = getUserSelection().getSelectedItem();
row[2] = getCallsReceivedJTextField().getText();
row[3] = getTicketsOpenedJTextField().getText();
row[4] = getTicketsClosedJTextField().getText();
row[5] = getVpnRequestsJTextField().getText();
row[6] = defaultFormat.format(fcr);
row[7] = getNotesJTextArea().getText();
model.addRow(row);
}
});
userInput.add(Buttons.createLogButton());
userInput.add(Buttons.createUpdateButton());
userInput.add(Labels.getCreditsJLabel());
//--------------------------------------//
this.displayInput = new JPanel();
displayInput.setBounds(330,16,825,700);
displayInput.setBorder(new TitledBorder("Stuff and things"));
displayInput.setLayout(new BorderLayout());
displayInput.setLayout(new BorderLayout());
displayInput.add(table.getTableHeader(), BorderLayout.PAGE_START);
displayInput.add(table, BorderLayout.CENTER);
JScrollPane pane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
pane.setSize(825,700);
displayInput.add(pane);
}
public JPanel getUserInput() {
return this.userInput;
}
public JPanel getDisplayInput(){
return this.displayInput;
}
}
Thanks in advance! If you need to see any other classes or need more information let me know! I have been trying to figure this out for several days now and really need another set of eyes to look it over.
You created log buttons two times. Try to change your code: