Click to See Complete Forum and Search --> : JTable, data variable call from class to another one !!!!!!!!


March 1st, 2000, 06:32 PM
This is the code :

// The TableModel controls all the data:
class DataModel extends AbstractTableModel {
Object[][] data = {
{"one", "two", "three", "four"},
{"five", "six", "seven", "eight"},
{"nine", "ten", "eleven", "twelve"},
};
// Prints data when table changes:
class TML implements TableModelListener {
public void tableChanged(TableModelEvent e) {
for(int i = 0; i < data.length; i++) {
for(int j = 0; j < data[0].length; j++)
System.out.print(data[i][j] + " ");
System.out.println();
}
}
}
DataModel() {
addTableModelListener(new TML());
}
.......
.......
};

public class Table extends JPanel {
public Table(Vector new_data) {
setLayout(new BorderLayout());
JButton next = new JButton("Next");

getContentPane().add(next);
next.addActionListener(this);
JTable table = new JTable(new DataModel());
JScrollPane scrollpane =
JTable.createScrollPaneForTable(table);
add(scrollpane, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e)
String s = getActionEvent();
if(s.equals("Next"))
//call change data, but I don't know how the variable data of DataModel
// class will be changed from over here.

public static void main(String args[]) {
JFrame frame = new JFrame("test jtable ");
frame.getContentPane().add(new Table());
//Show.inFrame(new Table(),200,200);
frame.show();

}
} ///:~




I am trying to create a JButton and a function called change_data in Table class.
When I press the button the function change_data is called, could you please show me how to implement this.