14. 59. 3.从AbstractTableModel继承 Extending AbstractTableModel

14. 59. 3.从AbstractTableModel继承 Extending AbstractTableModelimportjava.awt.BorderLayout;importjava.awt.Container;importjava.util.Calendar;importjava.util.GregorianCalendar;importjavax.swing.JFrame;importjavax.swing.JTable;importjavax.swing.tabl…

14. 59. 3.从AbstractTableModel继承 Extending AbstractTableModel

import java.awt.BorderLayout; import java.awt.Container; import java.util.Calendar; import java.util.GregorianCalendar; import javax.swing.JFrame; import javax.swing.JTable; import javax.swing.table.AbstractTableModel; class TableValues extends AbstractTableModel{ //public final static int FIRST_NAME = 0;//名 //public final static int LAST_NAME = 1;//姓 //public final static int DATE_OF_BIRTH = 2;//生日 //public final static int ACCOUNT_BALANCE = 3;//balance:平衡 //public final static int GENDER = 4;//性别 public final static boolean GENDER_MALE = true;//男 public final static boolean GENDER_FEMALE = false;//女 public Object[][] values = { { “康”, “杜”, new GregorianCalendar(1962, Calendar.FEBRUARY, 20).getTime(), new Float(15.67), new Boolean(GENDER_MALE) }, { “白”, “李”, new GregorianCalendar(1987, Calendar.JANUARY, 6).getTime(), new Float(2.78), new Boolean(GENDER_MALE) }, { “中山”, “孙”, new GregorianCalendar(1989, Calendar.AUGUST, 31).getTime(), new Float(3.89), new Boolean(GENDER_FEMALE) }, { “学良”, “张”, new GregorianCalendar(1945, Calendar.JANUARY, 16).getTime(), new Float(-4.70), new Boolean(GENDER_FEMALE) }, { “谨”, “秋”, new GregorianCalendar(1907, Calendar.AUGUST, 2).getTime(), new Float(5.00), new Boolean(GENDER_FEMALE) }}; public int getColumnCount() {//拿到列 return values.length; } public int getRowCount() {//拿到行数 return values[0].length;//values[0]的列数是:5 } public Object getValueAt(int row, int col) {//拿到单元格的值 return values[row][col]; } } public class ExtendingAbstractTableModel extends JFrame{ protected JTable table; public static void main(String[] args) { ExtendingAbstractTableModel eat = new ExtendingAbstractTableModel(); eat.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); eat.setSize(400,200); eat.setVisible(true); } public ExtendingAbstractTableModel(){ Container pane = getContentPane(); pane.setLayout(new BorderLayout()); TableValues tv = new TableValues(); table = new JTable(tv); pane.add(table,BorderLayout.CENTER); } }

今天的文章14. 59. 3.从AbstractTableModel继承 Extending AbstractTableModel分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/31223.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注