1、1.登录界面和主界面import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.awt.*;import java.awt.event.*;import java.sql.*;class myConnectionResultSet re; public myConnection() public ResultSet getResult(String sql) tryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver); Connection conn=DriverMan
2、ager.getConnection(jdbc:odbc:学生成绩管理系统,ww123 Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet re=stmt.executeQuery(sql); return re; catch(Exception e) System.out.println(getResult-+e.toString(); return null; public boolean executeSql(String sq
3、l) Statement stmt=conn.createStatement(); stmt.executeUpdate(sql); mit(); return true;executeSql- return false; class stuMainFrame extends JFrame implements ActionListenerJMenuBar jmb = new JMenuBar(); Message = new JMenu(信息 JMenu Score = new JMenu(查询 JMenuItem Item1 = new JMenuItem(添加学生信息 JMenuItem
4、 mName=new JMenuItem(学生成绩查询 JMenuItem mScore=new JMenuItem(按成绩查询 JMenuItem mNam1=new JMenuItem(查询学生信息 JLabel label = new JLabel(); public stuMainFrame()ImageIcon icon = new ImageIcon(src/images/1.jpg label.setIcon(icon); label.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight(); add(label); se
5、tSize(label.getWidth(),label.getHeight(); this.setJMenuBar(jmb); jmb.add(Message); jmb.add(Score); Message.add(Item1); Score.add(mNam1); Score.add(mName); Score.add(mScore); Item1.addActionListener(this); mName.addActionListener(this); mScore.addActionListener(this); mNam1.addActionListener(this); p
6、ublic void actionPerformed(ActionEvent e) if(e.getSource()=Item1) new addForm().setVisible(true); else if(e.getSource()=mName) dispose(); new Score1().setVisible(true); else if(e.getSource()=mScore) new scoreQueryForm().setVisible(true); else if(e.getSource()=mNam1) dispose(); new Serch1().setVisibl
7、e(true); class mainFrame extends JFrame implements ActionListener JLabel label = new JLabel(); JMenuBar mBar= new JMenuBar(); JPanel p=new JPanel(); private JMenu mSystem,mOperate,mQuery,mHelp,myMenuUser; private JMenuItem mFile,mNew,mOpen,mExit,mAdd,mDel,mModify,mName,miShow,mScore,mAbout,miUser,mA
8、ddSc; public mainFrame() this.setJMenuBar(mBar); ImageIcon icon = new ImageIcon( label.setIcon(icon); label.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight(); add(label); setSize(label.getWidth(),label.getHeight(); myMenuUser=new JMenu(用户 miUser=new JMenuItem(编辑用户 myMenuUser.add(miUser); mSy
9、stem=new JMenu(系统 mOperate=new JMenu(数据操作 mQuery=new JMenu( mHelp=new JMenu(帮助 mBar.add(mSystem); mBar.add(mOperate); mBar.add(mQuery); mBar.add(mHelp); mBar.add(myMenuUser); mFile=new JMenuItem(文件 mNew=new JMenuItem(新建 mOpen=new JMenuItem(打开 mExit=new JMenuItem(退出 mSystem.add(mFile); mSystem.add(mN
10、ew); mSystem.add(mOpen); mSystem.addSeparator(); mSystem.add(mExit); mAdd=new JMenuItem(添加基本信息 mAddSc=new JMenuItem(添加成绩信息 mDel=new JMenuItem(删除 mModify=new JMenuItem(修改 mOperate.add(mAdd); mOperate.add(mAddSc); mOperate.add(mDel); mOperate.add(mModify); mName=new JMenuItem( mScore=new JMenuItem(查询学
11、生成绩 miShow=new JMenuItem(全部显示 mQuery.add(mName); mQuery.add(mScore); mQuery.addSeparator(); mQuery.add(miShow); mAbout=new JMenuItem(软件信息 mHelp.add(mAbout); mExit.addActionListener(this); mAdd.addActionListener(this); mDel.addActionListener(this); mModify.addActionListener(this); mName.addActionList
12、ener(this); mScore.addActionListener(this); mAbout.addActionListener(this); miShow.addActionListener(this); miUser.addActionListener(this); mAddSc.addActionListener(this); public void actionPerformed(ActionEvent e) if(e.getSource()=mExit) dispose(); new CJ().setVisible(true); else if(e.getSource()=m
13、About) JOptionPane.showMessageDialog(this,学生成绩管理系统nn电信学院nn2012年3月,JOptionPane.INFORMATION_MESSAGE); else if(e.getSource()=mAdd) dispose(); new addForm().setVisible(true); else if(e.getSource()=mAddSc) new addScore().setVisible(true); else if(e.getSource()=mDel) new deleteForm().setVisible(true); els
14、e if(e.getSource()=mName) new Serch().setVisible(true); else if(e.getSource()=mScore) new Score().setVisible(true); else if(e.getSource()=mModify) new modifyForm().setVisible(true); else if(e.getSource()=miUser) new userFrame().setVisible(true); else if(e.getSource()=miShow) new freshTable().setVisi
15、ble(true); class CJ extends JFrame implements ActionListener JLabel t1=new JLabel(ID号: JLabel t3=new JLabel(密码: public String zh=null; JTextField t2=new JTextField(null,15); JTextField t4=new JPasswordField(null,15); JRadioButton b=new JRadioButton(教师 JRadioButton b1=new JRadioButton(学生 JButton jB1=
16、new JButton(登录 JButton jB2=new JButton(取消 public CJ ()super(学生生成绩管理系统 setLayout(null); jB1.setBounds(110,170,60,20); jB1.setBackground(Color.red); add(jB1); jB2.setBounds(210,170,60,20); jB2.setBackground(Color.red); add(jB2); t1.setBounds(90,50,80,35); add(t1); t2.setBounds(120,50,150,35); add(t2);
17、 t3.setBounds(90,100,80,35); add(t3); t4.setBounds(120,100,150,35); add(t4); b.setBounds(200,20,70,30); b1.setBounds(120,20,70,30); ButtonGroup bg=new ButtonGroup(); b.setSelected(false); b1.setSelected(true); b1.setSelected(false); add(b);bg.add(b);add(b1); bg.add(b1); b.setContentAreaFilled(false)
18、; b1.setContentAreaFilled(false); ImageIcon icon = new ImageIcon(src/images/a.jpg setResizable(false); setVisible(true); setLocation(300,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jB1.addActionListener(this); jB2.addActionListener(this); public void actionPerformed(ActionEvent e) if (e.ge
19、tSource()=jB2) System.exit(0); else if (e.getSource()=jB1) String username , password; username = t2.getText(); password = t4.getText(); if(b.isSelected() if (username.toString().equals() JOptionPane.showMessageDialog(null, 请输入用户名, 温馨提示, JOptionPane.INFORMATION_MESSAGE); else if (password.toString()
20、.equals(请输入密码 else myConnection conn=new myConnection(); ResultSet rs; String sql=select * from 教师信息表 where 教师ID=+username.toString()+ and 登录密码 = +password.toString()+; try rs=conn.getResult(sql); rs.last(); if(rs.getRow()=1) setVisible(false); rs.beforeFirst(); while(rs.next() this.dispose(); sql=s
21、elect * from 学籍信息表 mainFrame mf=new mainFrame(); mf.setLayout(null); mf.setVisible(true); mf.setLocation(300,300); mf.setResizable(false); mf.setTitle(学生成绩管理系统:教师登录界面 mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mf.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e)
22、System.exit(0); ); JOptionPane.showMessageDialog( null ,rs.getString(教师姓名)+老师!您好!欢迎登录学生成绩管理系统! ) ; else 用户名或密码错误登录失败 catch(Exception er) System.out.println(er.toString(); if(b1.isSelected() select * from 学籍信息表 where 学号=+t2.getText().toString()+t4.getText().toString()+ stuMainFrame smf =new stuMainFrame(); smf.setSize(500,400); smf.setVisible(true); smf.setResizable(false); smf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); smf.addWindowListener(new WindowAdapter() ); JOptionPane.showMessageDialog( null ,rs.ge
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1