可能重复:
矩阵到 JTable
这个功能好像有问题。我已经为 jTable 创建了一个模型,但它没有得到我需要的值。这是代码:
public class InsertMatToJTable extends AbstractTableModel{
String titre[] = {"age real", "sex real", "chest real", "resting_blood_pressure real", "serum_cholestoral real","fasting_blood_sugar real","resting_electrocardiographic_results real","maximum_heart_rate_achieved real","exercise_induced_angina real","oldpeak real","slope real","number_of_major_vessels real","thal real", "class"};
String line;
float mat[][]= new float[370][13];
float matrice_normalise[][]=new float[270][13];;
int i = 1,j=1;
Vector data;
public void InsertMatToJTable()
{data= new Vector();
try {
FileInputStream fis = new FileInputStream("fichier.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((line = br.readLine()) != null) {
StringTokenizer st1 = new StringTokenizer(line, " ");
while (st1.hasMoreTokens())
{mat[i][j]=Float.valueOf(st1.nextToken()).floatValue();
j++;
if (j==13) {i++;j=1;}
}
}
br.close();
}catch(Exception e) {
e.printStackTrace();}
Normalisation norm = new Normalisation(mat);
// for(i=0;i<270;i++)
//{for(j=0; j<14;j++)
//{matrice_normalise[i][j]=norm.mat_normalised[i][j];
//}
matrice_normalise=norm.mat_normalised;
}
@Override
public int getRowCount() {
return 270;
}
@Override
public int getColumnCount() {
return 13;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return matrice_normalise[rowIndex][columnIndex];
}
public String getColumnName(int columnIndex) {
return titre[columnIndex];
}
}
文本文件读取完成。该matrice_normalise=norm.mat_normalised;
部分也有效。我已经分别对它们进行了测试,并且它们起作用了。
但是,表中填充了 0.0,它没有从matrice_normalise
.