java制作课程表:新建工程,工程中新建两个类KCBData、KCB。KCBData用于存 放Table表格数据,KCB实现窗体。
java制作课程表代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
package kcb; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class KCB { public static void main(String[] args) { // TODO Auto-generated method stub JFrame frame = new JFrame(); JTable table = new JTable(new KCBData()); JScrollPane Pane = new JScrollPane(table); frame.add(Pane); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
package kcb; import javax.swing.event.TableModelListener; import javax.swing.table.TableModel; public class KCBData implements TableModel { private String[] title = { "周一", "周二", "周三", "周四", "周五", "周六", "周七", }; private String[][] data = new String[8][7]; public KCBData() { for(int i=0;i<data.length;i++) { for(int j=0;j<data[i].length;j++) { data[i][j] = ""; } } } @Override public void addTableModelListener(TableModelListener arg0) { // TODO Auto-generated method stub } @Override public Class<?> getColumnClass(int arg0) { return String.class; } @Override public int getColumnCount() { return 7; } @Override public String getColumnName(int arg0) { return title[arg0]; } @Override public int getRowCount() { // TODO Auto-generated method stub return 8; } @Override public Object getValueAt(int arg0, int arg1) { // TODO Auto-generated method stub return data[arg0][arg1]; } @Override public boolean isCellEditable(int arg0, int arg1) { // TODO Auto-generated method stub return true; } @Override public void removeTableModelListener(TableModelListener arg0) { // TODO Auto-generated method stub } @Override public void setValueAt(Object arg0, int arg1, int arg2) { // TODO Auto-generated method stub data[arg1][arg2] = (String)(arg0); } } |
java制作课程表实现效果: