JTable(Vector rowData,Vector columnNames) package table;public class grade{String name;int china;int math;int all;boolean ok;public grade(String name,int china,int math,int all,boolean ok) {this.name = name;this.china = china;this.math = math;this.al

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 04:37:02
JTable(VectorrowData,VectorcolumnNames)packagetable;publicclassgrade{Stringname;intchina;intmath;int

JTable(Vector rowData,Vector columnNames) package table;public class grade{String name;int china;int math;int all;boolean ok;public grade(String name,int china,int math,int all,boolean ok) {this.name = name;this.china = china;this.math = math;this.al
JTable(Vector rowData,Vector columnNames)
package table;
public class grade
{
String name;
int china;
int math;
int all;
boolean ok;
public grade(String name,int china,int math,int all,boolean ok)
{
this.name = name;
this.china = china;
this.math = math;
this.all = all;
this.ok = ok;
}
}
package table;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Vector;
import javax.swing.*;
public class table
{
public table()
{
JFrame f=new JFrame();
Vector va=new Vector();
grade gr1=new grade("网鹏",new Integer(82),new Integer(91),new Integer(100),new Boolean(true));
grade gr2=new grade("网",new Integer(82),new Integer(91),new Integer(100),new Boolean(true));
grade gr=new grade("鹏",new Integer(82),new Integer(91),new Integer(100),new Boolean(true));
va.addElement(gr);
va.addElement(gr2);
va.addElement(gr1);
Vector ve=new Vector();
ve.add("姓名");
ve.add("语文");
ve.add("数学");
ve.add("总分");
ve.add("及格");
JTable table=new JTable(va,ve); // 这里报错为什么啊
table.setPreferredScrollableViewportSize(new Dimension(550,30));
JScrollPane scrollPane=new JScrollPane(table);
f.getContentPane().add(scrollPane,BorderLayout.CENTER);
f.setTitle("表格测试窗口");
f.pack();
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
new table();
}
}

JTable(Vector rowData,Vector columnNames) package table;public class grade{String name;int china;int math;int all;boolean ok;public grade(String name,int china,int math,int all,boolean ok) {this.name = name;this.china = china;this.math = math;this.al
你的Vector va=new Vector()里面的数据类型都是grade的,而grade又不是数组,所以你的va里面都是一个一个的grade对象,JTable不会自动解析你的grade的构造方法,把它变成String数组,所以你要手动提取出gr1,gr2,gr3中你所需要的数据然后加在不同的Vector对象里面,再把这些Vector对象add到一个Vector类型的对象里面,然后再JTable的构造方法里用这个Vector的对象就可以了