This is for Hard, but anyone can look through.
This code is the main file provided by my teammate.
[code]package teamB;
import java.awt.;
import java.awt.event.;
import java.io.IOException;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
public class PledgeApp extends JFrame {
private static final long serialVersionUID = 1L;
private static final int W = 1300,
H = 700;
private static String[] US_STATES = {“AK”, “AL”, “AR”, “AS”, “AZ”, “CA”,“CO”,“CT”,“DC”,“DE”,“FL”,“GA”,“GU”,“HI”,“IA”,“ID”,
“IL”,“IN”,“KS”,“KY”,“LA”,“MA”,“MD”,“ME”,“MH”,“MI”,“MN”,“MO”,“MS”,“MT”,“NC”,“ND”,“NE”,“NH”,“NJ”,“NM”,“NV”,“NY”,
“OH”,“OK”,“OR”,“PA”,“PR”,“PW”,“RI”,“SC”,“SD”,“TN”,“TX”,“UT”,“VA”,“VI”,“VT”,“WA”,“WI”,“WV”,“WY”};
private int selectedCharityID;
private Pledge pledge;
public PledgeApp() {
super ("Pledge App");
this.pledge = new Pledge();
this.add(new DonorPane());
this.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent arg0) {
super.windowClosing(arg0);
System.exit(0);
}
});
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public static void main(String[] args) {
new PledgeApp();
}
public static class DonorPane extends JPanel {
private static final long serialVersionUID = 1L;
public static final String[] DONOR_COLUMNS = {
" ID", "First Name", "Last Name", "Address", "City", "State", "Zip Code", "Phone", "Email"};
private int selectedDonor;
private QueryDB query;
private TableModel tblModel;
private JTable table;
private JTextField fName, lName, address, city, zip, phone, email;
private JComboBox state;
private JLabel info;
private JButton btnAdd, btnAll, next;
public DonorPane(){
this.setPreferredSize(new Dimension(W, H));
this.setLayout(new BorderLayout());
JPanel pn0, pn1;
pn0 = new JPanel(new GridLayout(3, 1));
try {
JEditorPane header = new JEditorPane("<h2 stye='align:center;'>Select a Donor from the list bellow, or add a new one, then click 'Next' </2>");
header.setOpaque(false);
pn0.add(header);
this.add(pn0, BorderLayout.NORTH);
} catch (IOException e) {
pn0.add(new JLabel("Select a charity from the list bellow"));
this.add(pn0, BorderLayout.NORTH);
}
pn1 = new JPanel(new GridLayout(2,);
pn1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20), "Add Donor"));
pn1.add(new JLabel("First Name ", JLabel.RIGHT));
fName = new JTextField();
pn1.add(fName);
pn1.add(new JLabel("Last Name ", JLabel.RIGHT));
lName = new JTextField();
pn1.add(lName);
pn1.add(new JLabel("Address ", JLabel.RIGHT));
address = new JTextField();
pn1.add(address);
pn1.add(new JLabel("City ", JLabel.RIGHT));
city = new JTextField();
pn1.add(city);
pn1.add(new JLabel("State ", JLabel.RIGHT));
state = new JComboBox(US_STATES);
pn1.add(state);
pn1.add(new JLabel("Zip ", JLabel.RIGHT));
zip = new JTextField();
pn1.add(zip);
pn1.add(new JLabel("Phone ", JLabel.RIGHT));
phone = new JTextField();
pn1.add(phone);
pn1.add(new JLabel("Email ", JLabel.RIGHT));
email = new JTextField();
pn1.add(email);
pn0.add(pn1);
pn1 = new JPanel();
pn0.add(pn1);
btnAdd = new JButton("Add");
btnAdd.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
query.addDonor(new Donor(0, fName.getText(), lName.getText(), address.getText(), city.getText(),
state.getSelectedItem().toString(), zip.getText(), phone.getText(), email.getText()));
btnAll.doClick();
}});
pn1.add(btnAdd);
this.btnAll = new JButton("Show All");
this.btnAll.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
query = new QueryDB();
String[][] data = query.getDonorArrayListToStringArray(query.getAllDonors());
tblModel = new DefaultTableModel(data, DONOR_COLUMNS);
table.setModel(tblModel);
}});
pn1.add(btnAll);
pn0 = new JPanel(new GridLayout(1, 1));
this.table = new JTable(){
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
this.table.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
@Override
public void valueChanged(ListSelectionEvent arg0) {
selectedDonor = Integer.parseInt(tblModel.getValueAt(table.getSelectedRow(), 0).toString());
info.setText("Selected Charity: " + tblModel.getValueAt(table.getSelectedRow(), 1) +
" (id: " + selectedDonor +")");
}});
this.btnAll.doClick();
pn0.add(new JScrollPane(table));
this.add(pn0, BorderLayout.CENTER);
[/code]