Thursday, May 29, 2008
Inticas 012: Entering Teachers via JTable
Above is Inticas 012.
Added capability of entering Teachers via JTable.
Just enter the teachers particulars directly into each cell.
Click on File/Save to save the Teacher data.
Also, when Teacher Frame is opened, it automatically reads the
TeacherSerialized.txt file and populates the JTable.
I also found out the JTable cannot accept integer values, only can
accept Strings. All number that is entered is entered as a String.
This is so, even though the default object value in each cell is Object.
As such, I had to modify the Teacher Class so that the maxTotal data type
is String instead of integers:
public class Teacher implements Serializable
{
private String name;
private String initials;
private boolean needBreak = false;
private int taughtToday;
private String maxTotal;
. . .
}
When extracting data from the cell, need to cast it to string:
//read table cells into Teacher Object
t[r]=new Teacher();
t[r].setName((String)teacherTable.getValueAt(r, 0));
t[r].setInitials((String)teacherTable.getValueAt(r, 1));
t[r].setmaxTotal((String)teacherTable.getValueAt(r, 2));
To Do:
Will add similar functionality for Entering Subjects using JTable and also
will add similar functionality for entering Classrooms using JTable.