登录 注册
当前位置:主页 > 资源下载 > 34 > 制作简单的JAVA表格

制作简单的JAVA表格

  • 更新:2024-12-09 15:32:02
  • 大小:1KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:Java - 后端
  • 格式:JAVA

资源介绍

利用JTABLE做简单的JAVA表格,package connect; import javax.swing.table.AbstractTableModel; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class complextable { public complextable(){ JFrame f=new JFrame(); mytable1 mt=new mytable1(); JTable t=new JTable(mt); t.setPreferredScrollableViewportSize(new Dimension(550, 30)); JScrollPane s = new JScrollPane(t); f.getContentPane().add(s, BorderLayout.CENTER); f.setTitle("JTable1"); f.pack(); f.setVisible(true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public static void main(String[] args) { complextable abc= new complextable(); } } class mytable1 extends AbstractTableModel{ Object[][] p={ {"阿呆", new Integer(66), new Integer(32), new Integer(98), new Boolean(false),new Boolean(false)}, {"阿瓜", new Integer(85), new Integer(69), new Integer(154), new Boolean(true),new Boolean(false)}, }; String[] n={"姓名", "语文", "数学", "总分", "及格", "作弊"}; public int getColumnCount() { return n.length; } public int getRowCount() { return p.length; } public String getColumnName(int col) { return n[col]; } public Object getValueAt(int row, int col) { return p[row][col]; } public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); } }