loseOperationJFrame.EXIT_ON_CLOSE frame.showpublic void stu_add Frame_Addnew JFramequot添加学生成绩quot //添加学生的窗口 Frame_Add.setResizablefalse Container conterPane JPanel pnew JPanel JLabel J1new JLabelquot 学号:quot JLabel J2new JLabelquot bel J6new JLabelquot 班级:quot JLabel J3new JLabelquot 英语:quot JLabel J4new JLabelquot 数学:quot JLabel J5new JLabelquot计算机:quot 6 JButton addnew JButtonquot添加quot add.addActionListenerthis //添加 JButton clearnew JButtonquot清空quot //清除 clear.addActionListenerthis JButton exitnew JButtonquot退出quot //退出 exit.addActionListenerthis GridBagLayout gridBagnew GridBagLayout GridBagConstraints gridBagCon numnew JTextField20 //学号 namenew JTextField20 //姓名 greatnew JTextField20 //计算机 englishnew JTextField20 //英语 mathnew JTextField20 //数学 computernew JTextField20 //计算机 p.addJ1 J1.setLabelFornump.addnum p.addJ2 J2.setLabelFornamep.addname p.addJ6 J6.setLabelForgreatp.addgreat p.addJ3 J3.setLabelForenglishp.addenglish p.addJ4 J4.setLabelFormathp.addmath p.addJ5 J5.setLabelForcomputerp.addcomputer p.addadd p.addclear p.addexit Frame_Add.setBounds300280300230 //窗口大小及开始在屏幕上的位置。
Frame_Add.addp Frame_Add.show public void stu_del Frame_Delnew JFramequot删除学生成绩quot //添加学生的窗口 Frame_Del.setResizablefalse Container conterPane JPanel pnew JPanel String XueHaoquotquot Data_
access DBnew Data_
access 7 Vector rec_vector new Vector //列名集合 int numberOfColumns try String queryquotSELECT ID FROM studentquot DB.rsDB.stmt.executeQueryquery whileDB.rs.next XueHao DB.rs.getString1 rec_vector.addElementXueHao catchException ex JOptionPane.showMessageDialog null quot连 接 数 据 库 失 败 quot quot数 据 连 接 quot JOptionPane.ERROR_MESSAGE plnew JComboBoxrec_vector pl.setEditabletrue pl.setPreferredSizenew Dimension13522 //框的长和高 pl.addActionListenerthis JLabel J1new JLabelquot 学号:quot JButton updatanew JButtonquot删除quot updata.addActionListenerthis //添加 JButton exit1new JButtonquotOUTquot //退出 exit1.addActionListenerthis GridBagLayout gridBagnew GridBagLayout GridBagConstraints gridBagCon p.addJ1p.addpl p.addupdata p.addexit1 Frame_Del.setBounds300280210100 //窗口大小及开始在屏幕上的位置。
Frame_Del.addp Frame_Del.show public void stu_updata 8 Frame_Updatanew JFramequot修改学生成绩quot //添加学生的窗口 Frame_Updata.setResizablefalse Container conterPane JPanel pnew JPanel String XueHaoquotquot Data_
access DBnew Data_
access Vector rec_vector new Vector //列名集合 int numberOfColumns try String queryquotSELECT ID FROM studentquot DB.rsDB.stmt.executeQueryquery whileDB.rs.next XueHaoDB.rs.getString1 rec_vector.addElementXueHao catchException ex JOptionPane.showMessageDialog null quot连 接 数 据 库 失 败 quot quot数 据 连 接 quot JOptionPane.ERROR_MESSAGE plnew JComboBoxrec_vector pl.setEditabletrue pl.setPreferredSizenew Dimension13522 //框的长和高 pl.addActionListenerthis JLabel J1new JLabelquot 学号:quot JLabel J2new JLabelquot bel J6new JLabelquot 班级:quot JLabel J3new JLabelquot 英语:quot JLabel J4new JLabelquot 数学:quot JLabel J5new JLabelquot计算机:quot JButton updatanew JButtonquot修改quot updata.addActionListenerthis //添加 JButton clear1new JButtonquot清空quot //清除 9 clear1.addActionListenerthis JButton exit1new JButtonquotOUTquot //退出 exit1.addActionListenerthis GridBagLayout gridBagnew GridBagLayout GridBagConstraints gridBagCon namenew JTextField12 //姓名 greatnew JTextField12 //计算机 englishnew JTextField12 //英语 mathnew JTextField12 //数学 computernew JTextField12 //计算机 p.addJ1p.addpl p.addJ2 J2.setLabelFornamep.addname p.addJ6 J6.setLabelForgreatp.addgreat p.addJ3 J3.setLabelForenglishp.addenglish p.addJ4 J4.setLabelFormathp.addmath p.addJ5 J5.setLabelForcomputerp.addcomputer p.addupdata p.addclear1 p.addexit1 Frame_Updata.setBounds300280210230 //窗口大小及开始在屏幕上的位置。
Frame_Updata.addp Frame_Updata.show public void stu_show Frame_Shownew JFramequot查看学生成绩quot //添加学生的窗口 Frame_Show.setResizablefalse Container conterPane JPanel pnew JPanel Data_
access DBnew Data_
access Vector rec_vector new Vector //列名集合 int numberOfColumns String XueHaoquotquot try String queryquotSELECT ID FROM studentquot DB.rsDB.stmt.executeQueryquery whileDB.rs.next 10 XueHao DB.rs.getString1 rec_vector.addElementXueHao catchException ex JOptionPane.showMessageDialog null quot连 接 数 据 库 失 败 quot quot数 据 连 接 quot JOptionPane.ERROR_MESSAGE plnew JComboBoxrec_vector pl.setEditabletrue pl.setPreferredSizenew Dimension13522 //框的长和高 pl.addActionListenerthis JLabel J1new JLabelquot 学号:quot JLabel J2new JLabelquot bel J6new JLabelquot 班级:quot JLabel J3new JLabelquot 英语:quot JLabel J4new JLabelquot 数学:quot JLabel J5new JLabelquot计算机:quot namenew JTextField12 //姓名 greatnew JTextField12 //计算机 englishnew JTextField12 //英语 mathnew JTextField12 //数学 computernew JTextField12 //计算机 name.setEditablefalse great.setEditablefalse english.setEditablefalse math.setEditablefalse computer.setEditablefalse p.addJ1p.addpl p.addJ2 J2.setLabelFornamep.addname p.addJ6 J6.setLabelForgreatp.addgreat p.addJ3 J3.setLabelForenglishp.addenglish p.addJ4 J4.setLabelFormathp.addmath p.addJ5 J5.setLabelForcomputerp.addcomputer JButton shownew JButtonquot查看quot show.addActionListenerthis p.addshow 11 Frame_Show.setBounds300280210230 //窗口大小及开始在屏幕上的位置。
Frame_Show.addp Frame_Show.show public int mian_JFrame throws Exception JPanel pane new JPanel frame1new JFramequot学生成绩管理系统quot JTable friendsnew JTable DefaultTableModel dtnew DefaultTableModel friends.setModeldt Vector vecColumnName new Vector //列名集合 int numberOfColumns int b1 Stu_Change Saddnew Stu_Change try Sadd.stuSum Data_
access DBnew Data_
access numberOfColumnsDB.rsmd.getColumnCount //以下是显示数据库中的列名的代码 dt.addColumnquot学号quot dt.addColumnquot姓名quot dt.addColumnquot班级quot dt.addColumnquot英语quot dt.addColumnquot数学quot dt.addColumnquot计算机quot dt.addColumnquot总分quot //以下是在表格中显示数据中的内容 whileDB.rs.next 12 Vector newRownew Vector int c1 whilecltnumberOfColumns newRow.addElementDB.rs.getStringc c dt.addRownewRow catchException ex JOptionPane.showMessageDialog null quot连 接 数 据 库 失 败 quot quot数 据 连 接 quot JOptionPane.ERROR_MESSAGE return 0 friends.setPreferredScrollableViewportSizenew Dimension580 200//设置表格的大小 friends.setRowHeight 25//设置每行的高度为 20 friends.setRowHeight 0 25//设置第 1 行的高度为 20 friends.setRowMargin 2//设置相邻两行单元格的距离 5 friends.setRowSelectionAllowed true//设置可否被选择.默认为 false friends.setSelectionBackground Color.white//设置所选择行的背景色 friends.setSelectionForeground Color.red//设置所选择行的前景色 friends.setGridColor Color.black//设置网格线的颜色 friends.clearSelection //取消选择 friends.setDragEnabled false//不懂这个 friends.setShowGrid false//是否显示网格线 friends.setShowHorizontalLines false//是否显示水平的网格线 friends.setShowVerticalLines true//是否显示垂直的网格线 // friends.setEditablefalse friends.doLayout friends.setBackground Color.lightGray JScrollPane pane3 new JScrollPane friends//JTable 最好加在 JScrollPane 上 pane.setPreferredSize new Dimension600300 pane.setBackground Color.orange 13 JPanel panel new JPanelnew FlowLayout JButton but1new JButtonquot添加数据quot setfontbut1 panel.addbut1 JButton but2new JButtonquot修改数据quot setfontbut2 panel.addbut2 JButton but3new JButtonquot删除数据quot setfontbut3 panel.addbut3 JButton but4new JButtonquot查看数据quot setfontbut4 panel.addbut4 JButton but5new JButtonquot保存退出quot setfontbut5 panel.addbut5 JPanel pane2 new JPanelnew BorderLayout JLabel labelnew JLabelquotxx 大学计算机学院 08 级 8 班 xxquot pane.add panelBorderLayout.PAGE_END pane.add pane3BorderLayout..