⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mytablemodel.java

📁 java数据库编程。JDBC+SQL+GUI。用java写的一个影碟租赁系统
💻 JAVA
字号:
//Vedio rental System Developed by Banu

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import java.awt.Dimension;
import java.awt.GridLayout;

/** 
 * 
 * Create a custom TableModel.
 */


class MyTableModel extends AbstractTableModel {
        private String[] columnNames; 
        private Object[][] data;

        // cunstructor
        public MyTableModel(String[] col, String[][] rows) {
			// Construct the Table Header
        	for (int i=0; i<col.length; i++)
        		columnNames[i] = col[i];
    	
        	//populate the data object with the rows passed. 
        	for(int j=0; j< rows.length;j++)
        	{
        		for (int i=0; i<col.length; i++){
        			data[j][i] = rows[j][i]; 
        		}
        	}
    		System.out.println("Table model construcor sucessed.");

		}

       	
        public int getColumnCount() {
            return columnNames.length;
        }

        public int getRowCount() {
            return data.length;
        }

        public String getColumnName(int col) {
            return columnNames[col];
        }

        public Object getValueAt(int row, int col) {
            return data[row][col];
        }

        /*
         * JTable uses this method to determine the default renderer/
         * editor for each cell.  
         */
        public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -