📄 managerframe.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package sports;import java.awt.*;import java.awt.Checkbox.*;import java.awt.event.* ;import java.sql.*;/** * * 该类是实现记分员登入系统后的界面 */public class ManagerFrame extends Frame implements ActionListener { CheckboxGroup ch; //Checkbox c1,c2; Button b1,b2,b3,b4; TextField t1,t2,t3,t4,t5,t6,t7,t8,t9; TextArea ta1; Connection conn ; Statement sm,sm2 ; ResultSet rs1,rs2 ; ManagerFrame(){ this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we1) { dispose(); } }); setSize(300,500); setBackground(Color.pink); setLocation(450,300); setResizable(false); setLayout(new FlowLayout(FlowLayout.TRAILING,10,5)); Label l1=new Label("参赛编号"); Label l2=new Label("姓名"); Label l3=new Label("性别"); Label l4=new Label("学院"); Label l5=new Label("年龄"); Label l6=new Label("项目"); Label l7=new Label("成绩"); Label l8=new Label("分数"); Label l9=new Label("名次"); b1=new Button("确定"); b2=new Button("返回"); b3=new Button("添加成绩"); b4=new Button("修改成绩"); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); t1=new TextField(25); t2=new TextField(25); t3=new TextField(25); t4=new TextField(25); t5=new TextField(25); t6=new TextField(25); t7=new TextField(25); t8=new TextField(25); t9=new TextField(25); ta1=new TextArea(5,38); ta1.setText("如要输入成绩,直接输入各项内容,点输入成绩,\n然后确定.\n如果修改成绩,先输入要改的参赛编号和项目,选\n择修改成绩,对要修改的栏目修改后点击确定"); add(l1);add(t1); add(l2);add(t2); add(l3);add(t3); add(l4);add(t4); add(l5);add(t5); add(l6);add(t6); add(l7);add(t7); add(l8);add(t8); add(l9);add(t9); add(b3);add(b4); add(b1); add(b2); add(ta1); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource() == b3){ try { Class.forName("com.mysql.jdbc.Driver"); } catch (java.lang.ClassNotFoundException ee){ System.out.println("驱动加载失败,属于系统错误,请与管理员联系!"); } try{ conn = DriverManager .getConnection("jdbc:mysql://localhost:3306/sports?user=root&password=root"); sm = conn.createStatement(); } catch (SQLException kk){ System.out.println("数据库连接失败,请查看服务器是否开启!"); } String SID=t1.getText(); String SNAME=t2.getText(); String SSEX=t3.getText(); String SDEPT=t4.getText(); int SAGE=Integer.parseInt(t5.getText()); String EVENT=t6.getText(); String RESULT=t7.getText(); int SCORE=Integer.parseInt(t8.getText()); String RANKING=t9.getText(); try{ sm.executeUpdate("insert into totalgame values('"+SID+"','"+SNAME+"','"+SSEX+"','"+ SDEPT+"',"+SAGE+",'"+EVENT+"','"+RESULT+"',"+SCORE+",'" +RANKING+ "')"); new ErrorDialog(this,"提示","已经成功添加"); } catch(SQLException j){ new ErrorDialog(this,"提示","数据操作失败"); } } else if (e.getSource() == b4){ try { Class.forName("com.mysql.jdbc.Driver"); } catch (java.lang.ClassNotFoundException ee){ System.out.println("驱动加载失败,属于系统错误,请与管理员联系!"); } try{ conn = DriverManager .getConnection("jdbc:mysql://localhost:3306/sports?user=root&password=root"); sm = conn.createStatement(); } catch (SQLException kk){ System.out.println("数据库连接失败,请查看服务器是否开启!"); } try{ String id=t1.getText(); String event=t6.getText(); rs2=sm.executeQuery("select * from totalgame where SID='"+id+"'"+"and EVENT= '"+event+"'"); int index1 = 0; while(rs2.next()){ index1=1; t1.setEditable(false); t2.setText((String)(rs2.getString(2))); t3.setText((String)rs2.getString(3)); t4.setText((String)rs2.getString(4)); t5.setText(String.valueOf(rs2.getInt(5))); t6.setText(rs2.getString(6)); t6.setEditable(false); t7.setText(rs2.getString(7)); t8.setText(String.valueOf(rs2.getInt(8))); t9.setText(rs2.getString(9)); } if(index1==0){ ta1.setText("您所输入的参赛编号或者项目有误"); } } catch(SQLException j){} } else if (e.getSource() == b1){ try { Class.forName("com.mysql.jdbc.Driver"); } catch (java.lang.ClassNotFoundException ee){ System.out.println("驱动加载失败,属于系统错误,请与管理员联系!"); } try{ conn = DriverManager .getConnection("jdbc:mysql://localhost:3306/sports?user=root&password=root"); sm = conn.createStatement(); } catch (SQLException kk){ System.out.println("数据库连接失败,请查看服务器是否开启!"); } try{ String SID=t1.getText(); String SNAME=t2.getText(); String SSEX=t3.getText(); String SDEPT=t4.getText(); int SAGE=Integer.parseInt(t5.getText()); String EVENT=t6.getText(); String RESULT=t7.getText(); int SCORE=Integer.parseInt(t8.getText()); String RANKING=t9.getText(); System.out.println(SID); System.out.println(Integer.parseInt(t5.getText())); sm.executeUpdate("update totalgame set SNAME='"+SNAME+"'where SID='"+SID+"'"); sm.executeUpdate("update totalgame set SSEX='"+SSEX+"'where SID='"+SID+"'"); sm.executeUpdate("update totalgame set SDEPT='"+SDEPT+"'where SID='"+SID+"'"); sm.executeUpdate("update totalgame set SAGE="+ SAGE+" where SID='"+SID+"'"); sm.executeUpdate("update totalgame set RESULT='"+RESULT+"'where SID='"+SID+"'"); sm.executeUpdate("update totalgame set SCORE="+SCORE+" where SID='"+SID+"'"); sm.executeUpdate("update totalgame set RANKING='"+RANKING+"'where SID='"+SID+"'"); new ErrorDialog(this,"提示","已经成功修改"); } catch(SQLException j){ j.printStackTrace(); new ErrorDialog(this,"提示","数据操作失败"); } } else if(e.getSource()==b2){ dispose(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -