methods in tablemodel not exposed?
Any idea why the doThis() method in this table model would not be
available?
When I try to compile, I get this error:
"cannot find symbol symbol : method doThis()
location: class javax.swing.JTable
t.doThis();"
(This is a cut and snip code sample from a larger project. Ignore all of
the bad imports unless it would affect it.)
import javax.swing.text.*;
import javax.swing.*;
import java.awt.*;
import java.lang.Exception.*;
import java.awt.event.*;
import javax.swing.table.*;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.io.*;
import java.util.*;
import java.text.*;
public class nsProject extends JFrame implements ActionListener
{
//the table - so I can swap data
JTable t = new JTable(new MyTableModel());
public class nsRecord {
public String recNum = null;
public String firstName = null;
public String lastName = null;
public String state = null;
public String strain = null;
public String newRecNum = null;
public String source = null;
}
class MyTableModel extends AbstractTableModel {
//assigning column names
private String[] columnNames = {"Record Number",
"First Name",
"Last Name",
"State",
"Strain",
"Source"};
private ArrayList datalist = new ArrayList();
//constructor one
public MyTableModel() {
}
//constructor two
public MyTableModel(ArrayList l) {
datalist.addAll(l);
}
public void doThis() {
}
public int changeAll(ArrayList l) {
datalist.clear();
datalist.addAll(l);
fireTableDataChanged();
return 0;
}
public void addOneRec(nsRecord nsRec) {
datalist.add(nsRec);
fireTableDataChanged();
}
public nsRecord getRecordAt(int row) {
return (nsRecord)datalist.get(row);
}
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return datalist.size();
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
nsRecord rec = (nsRecord) datalist.get(row);
switch (col) {
case 0:
return rec.recNum;
case 1:
return rec.firstName;
case 2:
return rec.lastName;
case 3:
return rec.state;
case 4:
return rec.strain;
case 5:
return rec.source;
default:
return null;
}
}
}
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
int intResult = 0;
if (arg == "Open") {
//add data to table
t.doThis();
}
}
}