Hey folks,
i've been working on this program here, and i've hit a roadblock. Everything compiles fine, and it runs alright. As you can see from the code, there's a window that opens with two buttons, one to display the contents of the ArrayList and another with a form that allows you to add a contact. The latter will not work, however, and i can't for the life of me figure out why. Here's the code, any help would be appreciated.
/** * This applet runs and provides two options; saving a new contact or displaying the database. Choosing to * view the database opens a window that will display the contents of the database. Choosing to save a new * contact will open up a window with a form that allows for the creation of a contact. Eventually, the * program will save this database into a .txt file, allowing for permanent storage of the ArrayList of * contacts present in the interface Storage. * * Cdeed * 4/28/11 * version 1.3 */ import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MainPage extends JApplet implements Storage { public void init() { JLabel title = new JLabel("Contact Database"); JButton save = new JButton("New Contact"); save.addActionListener(new ButtonListener()); JButton view = new JButton("View Database"); view.addActionListener(new ButtonListener1()); Container c = getContentPane(); c.setBackground(Color.WHITE); c.setLayout(new BoxLayout(c, BoxLayout.PAGE_AXIS)); c.add(title); c.add(save); c.add(view); } private class ButtonListener implements ActionListener { private JTextField input, i1, i2, i3, i4; public void actionPerformed(ActionEvent event) { JFrame frame = new JFrame("New Contact"); frame.getContentPane().setBackground(Color.WHITE); frame.getContentPane().setLayout(new FlowLayout()); JLabel label = new JLabel ("Name"); input = new JTextField (15); JLabel l1 = new JLabel ("Address"); i1 = new JTextField (30); JLabel l2 = new JLabel ("Cell Number"); i2 = new JTextField (15); JLabel l3 = new JLabel ("Home Number"); i3 = new JTextField (15); JLabel l4 = new JLabel ("E-Mail"); i4 = new JTextField (30); JButton save = new JButton("Save"); save.addActionListener(new ButtonListener2()); frame.getContentPane().add(save); frame.getContentPane().setLayout(new BoxLayout(frame, BoxLayout.PAGE_AXIS)); frame.getContentPane().add(label); frame.getContentPane().add(input); frame.getContentPane().add(l1); frame.getContentPane().add(i1); frame.getContentPane().add(l2); frame.getContentPane().add(i2); frame.getContentPane().add(l3); frame.getContentPane().add(i3); frame.getContentPane().add(l4); frame.getContentPane().add(i4); frame.pack(); frame.setVisible(true); } private class ButtonListener2 implements ActionListener { public void actionPerformed(ActionEvent event) { Person p1 = new Person(i2.getText(), i3.getText(), input.getText(), i1.getText(), i4.getText()); contacts.add(p1); input.setText("Saved!"); i1.setText("Saved!"); i2.setText("Saved!"); i3.setText("Saved!"); i4.setText("Saved!"); } } } private class ButtonListener1 implements ActionListener { public void actionPerformed(ActionEvent event) { JFrame frame = new JFrame("Contacts"); frame.getContentPane().setBackground(Color.WHITE); frame.getContentPane().setLayout(new FlowLayout()); for(Person a: contacts) { JLabel b1 = new JLabel(a.toString()); frame.getContentPane().add(b1); } frame.pack(); frame.setVisible(true); } } }