I made a method called addToList that takes an ArrayList and an object as parameters. Evidently it it supposed to add the object to the list. My class for the dialog box looks like this now:
PHP Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
public class NewFilmDialog extends JFrame{
protected JLabel label1;
protected JTextField field1;
protected JLabel label2;
protected JTextField field2;
protected JLabel label3;
protected JTextField field3;
protected JLabel label4;
protected JTextField field4;
protected JLabel label5;
protected JTextField field5;
protected JLabel label6;
protected JTextField field6;
public JButton createNew;
public NewFilmDialog(){
super("Ny Film");
setLayout(new FlowLayout());
label1 = new JLabel(" Title: ");
field1 = new JTextField(10);
label2 = new JLabel(" Producer: ");
field2 = new JTextField(10);
label3 = new JLabel( " PublicationYear: ");
field3 = new JTextField(10);
label4 = new JLabel(" length: ");
field4 = new JTextField(10);
label5 = new JLabel(" Genre: ");
field5 = new JTextField(10);
label6 = new JLabel(" Age limit: ");
field6 = new JTextField(10);
createNew = new JButton("Create new");
add(label1);
add(field1);
add(label2);
add(field2);
add(label3);
add(field3);
add(label4);
add(field4);
add(label5);
add(field5);
add(label6);
add(field6);
add(createNew);
EventHandler handler = new EventHandler(); // Here I get compilation error,"The constructor NewFilmDialog.EventHandler() is
// undefined"
createNew.addActionListener(handler);
}
public class EventHandler implements ActionListener{
public String title, producer, pubYear, genre;
public int length, ageLimit;
Film addFilm;
public EventHandler(AbstractTableModel table){
}
public void actionPerformed(ActionEvent event){
if(event.getSource() == createNew)
addFilm = new Film(field1.getText(),field2.getText(),false,field3.getText(),Integer.parseInt(field4.getText()),Integer.parseInt(field6.getText()),field5.getText());
addToList(lm,addFilm); // Here I get the error" lm cannot be resolved"
}
public void addToList(ArrayList list, Object o){
list.add(o);
}
}
}
But the problem remains, lm cannot be resolved according to Eclipse. I understand that it needs a reference, I just can't see how I could change the code ao it does that.
One more time: lm is an object of the type LendingModel, which is an AbstractTableModel.
Thanks copeg and anyone who may help me.