java课程设计
- 格式:doc
- 大小:463.35 KB
- 文档页数:32
多客户网络聊天程序与学生成绩管理系统2014 年 1 月目录1 设计题目.................................................................2 设计目的.................................................................3 设计原理及方案...........................................................3.1 使用的软件工具和环境.....................................................3.2 需求分析与概要设计.......................................................3.3 数据库设计...............................................................3.4 核心代码.................................................................4 运行效果.................................................................5、设计体会.................................................................1·设计题目:I多客户网络聊天程序II学生成绩管理系统2·设计的目的I·基于Client/Server模式,采用Socket通讯方式。
服务器端采用多线程方式实现实现多客户同时聊天服务器端采用JDBC-ODBC连接Access数据库,实现客户端注册用户及登录验证操作。
II·采用J2SE实现单机的学生学籍管理系统采用JDBC-ODBC连接Access数据库功能包括:学生成绩的输入、查询、修改及删除。
3·设计原理及方案3.1使用的软件工具和环境使用的软件:myeclipse、mysql使用的环境:window3.2需求分析和概要设计I·多客户网络聊天程序:需求分析:当今社会,很多时候的聊天方式并不是两个人的对话,而是多人对话的模式,那么如果在原先的聊天工具的基础上添加多人聊天功能,那么会有更大的市场让我们所开发。
概要设计:首先应用Client/Server模式,采用多线程,实现多人聊天。
然后再应用数据库进行登录的验证与注册,注册就是在数据库中添加数据。
这里我将采用mysql数据库。
最后进行增删改查的编写。
II·学生成绩管理系统需求分析:现在正处于数据时代,对于整个社会,不管是像淘宝、京东、或者学校,班级,对于数据的管理都是重中之重。
对于数据的管理系统需求量也成正比的日趋加大。
一款有效的系统,能够为客户提供更多便利,也为商家更好的管理,获得更多的客户。
所以管理系统在社会上的需求量也可想而知。
概要设计:首先应用图形用户界面设计设计出主界面(这里我们将不再设计动态登录验证,因为前面一个设计已经说明了,为了简单起见,这里我们直接应用固定的名称进行登录)然后设计操作界面,有增删改查和返回、退出系统六个功能。
然后设计相应的界面。
最后连接数据库,进行动态的数据交互。
3.3数据库设计:多用户聊天:create database user;use user;set names gbk;create table register(nicheng varchar(20) primarykey,pass_word varchar(20));学生管理系统:show databases;create database administration;use administration;set names gbk;create table message(xuehao varchar(20) primary key,name varchar(20),class_1 varchar(20),birthday varchar(20),english varchar(20),java1 varchar(20), probabilism varchar(20),network varchar(20),graphtheory varchar(20) );3.4核心代码:I多用户聊天:客户端:public Client() {pNorth = new JPanel();pSouth = new JPanel();nameText = new JTextField(8);inputPassword = new JPasswordField(8);inputPassword.setEchoChar('*');inputIp = new JTextField(8);inputText = new JTextField(22);denglu = new JButton("登陆");register = new JButton("注册");send = new JButton("发送");send.setEnabled(false);chatArea = new JTextArea();pNorth.add(new JLabel("用户名:"));pNorth.add(nameText);pNorth.add(new JLabel("密码:"));pNorth.add(inputPassword);pNorth.add(new JLabel("IP:"));pNorth.add(inputIp);pNorth.add(denglu);pNorth.add(register);pSouth.add(new JLabel("输入聊天内容:"));pSouth.add(inputText);pSouth.add(send);nameText.addActionListener(this);// 监听inputPassword.addActionListener(this);inputIp.addActionListener(this);denglu.addActionListener(this);register.addActionListener(this);send.addActionListener(this);thread = new Thread(this);// thread.start();add(pNorth, BorderLayout.NORTH);add(pSouth, BorderLayout.SOUTH);add(chatArea, BorderLayout.CENTER);setTitle("welcom to chat 2014");setBounds(200, 100, 800, 500);setVisible(true);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);try {socket = new Socket("localhost", 3444);in = new DataInputStream(socket.getInputStream());out = new DataOutputStream(socket.getOutputStream());} catch (UnknownHostException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}if (!(thread.isAlive())) {thread = new Thread(this);thread.start();}}public void run() {while (true) {try {String s = in.readUTF();chatArea.append(s + "\n");} catch (IOException e) {chatArea.append("与服务器断开连接...");break;}}}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e) { if (e.getSource() == register) {try {name = nameText.getText();String text = inputPassword.getText();pass_word = text;out.writeUTF("注册:" + name);out.writeUTF(pass_word);} catch (UnknownHostException e2) {} catch (IOException e2) {chatArea.setText("服务器连接关闭");}}if (e.getSource() == denglu) {name = nameText.getText();String text = inputPassword.getText();pass_word = text;try {out.writeUTF("登陆:" + name);out.writeUTF(pass_word);} catch (IOException e1) {e1.printStackTrace();}send.setEnabled(true);}if (e.getSource() == send) {String s = inputText.getText();if (s != null) {try {out.writeUTF("聊天内容:" + name + ":" + s);out.writeUTF(nameText.getText());} catch (IOException e1) {e1.printStackTrace();}}inputText.setText("");}}@SuppressWarnings("unused")public static void main(String[] args) {Client c = new Client();}}服务器端:public class Server {public static void main(String[] args) {ServerSocket server = null;ServerThread thread = null;Socket socket = null;Hashtable peopleList;peopleList = new Hashtable();while (true) {try {server = new ServerSocket(3444);System.out.println("服务器启动成功...");} catch (IOException e) {System.out.println("正在监听...");}try {socket = server.accept();InetAddress address = socket.getInetAddress();System.out.println("客户的地址:" + address);} catch (IOException e) {System.out.println("正在等待客户...");}if (socket != null) {thread = new ServerThread(socket, peopleList);thread.start();} elsecontinue;}}}class ServerThread extends Thread {Socket socket;DataInputStream in = null;DataOutputStream out = null;String s = null;Connection con;Statement sql;ResultSet rs;Hashtable peopleList = null;ServerThread(Socket t, Hashtable list) {socket = t;peopleList = list;try {in = new DataInputStream(socket.getInputStream());out = new DataOutputStream(socket.getOutputStream());} catch (IOException e) {e.printStackTrace();}}public Connection getConnection() throws SQLException { Connection conn = null;try {Class.forName("com.mysql.jdbc.Driver");conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/user", "root", "123");} catch (ClassNotFoundException e) {e.printStackTrace();}return conn;}//登录验证与注册@SuppressWarnings("unchecked")public void run() {while (true) {String nicheng = null;String pass_word = null;String s = null;try {s = in.readUTF();} catch (IOException e1) {}if (s.startsWith("注册:")) {try {pass_word = in.readUTF();nicheng = s.substring(s.indexOf(":") + 1);con = this.getConnection();sql = con.createStatement();rs= sql.executeQuery("Select * from register where nicheng='"+ nicheng + "'");boolean boo = rs.next();if (boo == true) {out.writeUTF("该用户已经注册,请重新输入!");} else {PreparedStatement ps = con.prepareStatement("Insert into register(nicheng,pass_word) values(?,?)");ps.setString(1, nicheng);ps.setString(2, pass_word);ps.executeUpdate();con.close();out.writeUTF(nicheng + " 注册成功!");}} catch (IOException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();}}if (s.startsWith("登陆:")) {try {pass_word = in.readUTF();nicheng = s.substring(s.indexOf(":") + 1);con = this.getConnection();sql = con.createStatement();rs= sql.executeQuery("Select * from register where nicheng='"+ nicheng + "'");boolean boo = rs.next();if (boo == false) {out.writeUTF("该户名不存在,请先注册!");} else {out.writeUTF(nicheng + "登陆成功!");peopleList.put(nicheng, this);con.close();}s = "";} catch (Exception e1) {e1.printStackTrace();}}if (s.startsWith("聊天内容:")) {try {nicheng = in.readUTF();String msg = s.substring(s.indexOf(":") + 1);Enumeration chatPersonList = peopleList.elements();while (chatPersonList.hasMoreElements()) {((ServerThread) chatPersonList.nextElement()).out.writeUTF(nicheng + " 说:" + msg);}} catch (Exception e) {e.printStackTrace();}}}}}II学生成绩管理系统://主函数public class ChengJiGuanLi {public static void main(String[] args) {new denglu();}}//操作界面和操作逻辑chuangkou1() {Toolkit kit = Toolkit.getDefaultToolkit();Image img = kit.getImage("zhuye.jpg");frame.setIconImage(img);p1 = new Panel();label = new Label("欢迎使用成绩管理系统", Label.CENTER);label.setFont(new Font("隶书", Font.BOLD, 30));label.setBackground(Color.green);p1.add(label);menubar = new JMenuBar();menu = new JMenu("操作");item1 = new JMenuItem("添加");item2 = new JMenuItem("删除");item3 = new JMenuItem("修改");item4 = new JMenuItem("单个查询");item5 = new JMenuItem("返回");item6 = new JMenuItem("退出");item7=new JMenuItem("查询所有");menu.add(item1);menu.add(item2);menu.add(item3);menu.add(item4);menu.add(item7);menu.add(item5);menu.add(item6);menubar.add(menu);p1.add(menubar);item1.addActionListener(this);item2.addActionListener(this);item3.addActionListener(this);item4.addActionListener(this);item5.addActionListener(this);item6.addActionListener(this);item7.addActionListener(this);addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {dispose();}});bg = new ImageIcon("zhuye.jpg");JLabel label = new JLabel(bg);label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight()); imagePanel = (JPanel) frame.getContentPane();imagePanel.setOpaque(false);imagePanel.setLayout(new FlowLayout());imagePanel.add(p1, BorderLayout.NORTH);frame.getLayeredPane().setLayout(null);frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭后状态frame.setSize(bg.getIconWidth(), bg.getIconHeight());frame.setBounds(200, 200, bg.getIconWidth(), bg.getIconHeight());frame.setResizable(false);// 设置窗口大小不可改变frame.setVisible(true);validate();}public void actionPerformed(ActionEvent e) {if (e.getSource() == item6) {System.exit(0);}if (e.getSource() == item1) {new charu();}if (e.getSource() == item2) {new shanchu1();}if (e.getSource() == item3) {new xiugai1();}if (e.getSource() == item4) {new chaxun1();}if(e.getSource()==item7){new findAllRecord();}if (e.getSource() == item5) {new denglu();frame.dispose();} else {}//插入charu() {Toolkit kit = Toolkit.getDefaultToolkit();Image img = kit.getImage("tubiao.jpg");frame.setIconImage(img);input1 = new TextField(10);input2 = new TextField(10);input3 = new TextField(10);input4 = new TextField(10);input5 = new TextField(10);input6 = new TextField(10);input7 = new TextField(10);input8 = new TextField(10);input9 = new TextField(10);box2 = Box.createVerticalBox();box2.add(input1);box2.add(Box.createVerticalStrut(8));box2.add(input2);box2.add(Box.createVerticalStrut(8));box2.add(input3);box2.add(Box.createVerticalStrut(8));box2.add(input4);box2.add(Box.createVerticalStrut(8));box2.add(input5);box2.add(Box.createVerticalStrut(8));box2.add(input6);box2.add(Box.createVerticalStrut(8));box2.add(input7);box2.add(Box.createVerticalStrut(8)); box2.add(input8);box2.add(Box.createVerticalStrut(8)); box2.add(input9);box1 = Box.createVerticalBox();box1.add(new Label("学号:"));box1.add(Box.createVerticalStrut(8)); box1.add(new Label("姓名:"));box1.add(Box.createVerticalStrut(8)); box1.add(new Label("班级:"));box1.add(Box.createVerticalStrut(8)); box1.add(new Label("生日:"));box1.add(Box.createVerticalStrut(8)); box1.add(new Label("英语:"));box1.add(Box.createVerticalStrut(8)); box1.add(new Label("java:"));box1.add(Box.createVerticalStrut(8)); box1.add(new Label("概率论:"));box1.add(Box.createVerticalStrut(8)); box1.add(new Label("网络:"));box1.add(Box.createVerticalStrut(8)); box1.add(new Label("图论:"));box3 = Box.createHorizontalBox();box3.add(box1);box3.add(Box.createHorizontalStrut(1)); box3.add(box2);show = new TextArea(6, 43);sure = new Button("确定");box4 = Box.createHorizontalBox();Label label1 = new Label("请输入数据");label1.setFont(new Font("宋体", Font.BOLD, 20));label1.setForeground(Color.blue);box4.add(label1);box4.add(Box.createHorizontalStrut(1));box4.add(sure);sure.addActionListener(this);bg = new ImageIcon("cru.jpg");JLabel label = new JLabel(bg);label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight()); imagePanel = (JPanel) frame.getContentPane();imagePanel.setOpaque(false);imagePanel.setLayout(new FlowLayout());show.setEditable(false);imagePanel.add(box4, BorderLayout.NORTH);imagePanel.add(box3, BorderLayout.CENTER);imagePanel.add(show, BorderLayout.SOUTH);frame.getLayeredPane().setLayout(null);frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE)); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(bg.getIconWidth(), bg.getIconHeight());frame.setBounds(700, 200, 540, 440);frame.setResizable(false);frame.setVisible(true);validate();addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {dispose();}});}public void actionPerformed(ActionEvent ee) {String s1, s2, s3, s4, s5, s6,s7,s8,s9,insert1, recode, name, birthday, xuehao,class_1;int m1, m2,m3,m4,m5, english,java1,probabilism,network,graphtheory;s1 = input1.getText();s2 = input2.getText();s3 = input3.getText();s4 = input4.getText();s5 = input5.getText();s6=input6.getText();s7=input7.getText();s8=input8.getText();s9=input9.getText();xuehao = s1;name = s2;class_1 = s3;birthday=s4;m1 = Integer.parseInt(s5);english = m1;m2 = Integer.parseInt(s6);java1 = m2;m3 = Integer.parseInt(s7);probabilism= m3;m4= Integer.parseInt(s8);network = m4;m5= Integer.parseInt(s9);graphtheory= m5;try {Class.forName("com.mysql.jdbc.Driver");} catch (ClassNotFoundException eee) {System.out.println("" + eee);}try {con = DriverManager.getConnection("jdbc:mysql://localhost:3306/administration","root", "123");sql = con.createStatement();recode = "(" + "'" + xuehao + "'" + "," + "'" + name + "'" + ","+ "'" + class_1 + "'" + "," + birthday + "," + english + ","+java1+","+probabilism+","+network+","+graphtheory+")";insert1 = "INSERT INTO MESSAGE VALUES " + recode;sql.executeUpdate(insert1);show.setText("你插入了:");show.append("学号:"+ xuehao + " 姓名:"+ name + " 生日:"+ birthday + " 班级: "+ class_1 + " 英语: "+ english+" java:"+java1+" 概率论:"+probabilism+" 网络:"+network+" 图论:"+graphtheory);show.append("\n");} catch (SQLException e) {System.out.println(e);JOptionPane.showMessageDialog(this, "你输入的学号已存在,请核对重新输入!");}}//删除shanchu1() {Toolkit kit = Toolkit.getDefaultToolkit();Image img = kit.getImage("tupian.jpg");frame.setIconImage(img);Panel p = new Panel();xunzhao = new Button("删除");input = new TextField(15);show = new TextArea(6, 43);Label l1 = new Label("输入要删除学生的学号");l1.setFont(new Font("宋体", Font.BOLD, 15));l1.setForeground(Color.BLUE);p.add(l1);p.add(input);p.add(xunzhao);xunzhao.addActionListener(this);show.setEditable(false);bg = new ImageIcon("tupian.jpg");JLabel label = new JLabel(bg);label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight()); imagePanel = (JPanel) frame.getContentPane();imagePanel.setOpaque(false);imagePanel.setLayout(new FlowLayout());imagePanel.add(p, BorderLayout.NORTH);imagePanel.add(show, BorderLayout.CENTER);frame.getLayeredPane().setLayout(null);frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE)); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(bg.getIconWidth(), bg.getIconHeight());frame.setBounds(710, 210, 480, 310);frame.setVisible(true);frame.setResizable(false);// 设置窗口大小不可改变validate();addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {dispose();}});}public void actionPerformed(ActionEvent ee) {boolean boo = true;s = input.getText();String m;try {Class.forName("com.mysql.jdbc.Driver");} catch (ClassNotFoundException eee) {System.out.println("" + eee);}try {con = DriverManager.getConnection("jdbc:mysql://localhost:3306/administration","root", "123");sql = con.createStatement();rs = sql.executeQuery("SELECT * FROM message");while (rs.next()) {String xuehao = rs.getString("xuehao");String name = rs.getString("name");String class_1 = rs.getString("class_1");String birthday = rs.getString("birthday");String english = rs.getString("english");String java1=rs.getString("java1");String probabilism=rs.getString("probabilism");String network=rs.getString("network");String graphtheory=rs.getString("graphtheory");if (xuehao.equals(s)) {show.setText("你删除了:");show.append("学号:" + xuehao + " 姓名:" + name + " 班级:"+ class_1 + " 生日: "+ birthday + " 英语 "+ english+" java"+java1+" 概率论"+probabilism+" 网络"+network+" 图论"+graphtheory);show.append("\n");m = "DELETE FROM message WHERE number = '"+ input.getText() + "'";sql.executeUpdate(m);}}con.close();if (boo) {JOptionPane.showMessageDialog(this, "你输入的学号不存在");}} catch (SQLException e) {System.out.println(e);}}//修改xiugai1() {Toolkit kit = Toolkit.getDefaultToolkit();Image img = kit.getImage("tupian.jpg");frame.setIconImage(img);hintLabel = new JLabel("输入学号:(回车确认)");inputNumber = new JTextField(20);table = new JTable(a, name1);entermodify = new JButton("更新记录");setLayout(null);Box baseBox = Box.createHorizontalBox();baseBox.add(hintLabel);baseBox.add(inputNumber);baseBox.add(new JScrollPane(table));baseBox.add(entermodify);add(baseBox);baseBox.setBounds(10, 20, 600, 38);inputNumber.addActionListener(this);entermodify.addActionListener(this);setBounds(20, 60, 700, 200);setVisible(true);validate();}public void actionPerformed(ActionEvent e) {if (e.getSource() == inputNumber)try {num = inputNumber.getText().trim();con = DriverManager.getConnection("jdbc:mysql://localhost:3306/administration", "root","123");sql = con.createStatement();rs = sql.executeQuery("select*from message where xuehao='"+ num + "'");boolean boo = rs.next();if (boo == false) {JOptionPane.showMessageDialog(this, "学号不存在", "提示",JOptionPane.WARNING_MESSAGE);} else {a[0][0] = rs.getString(2);a[0][1] = rs.getString(3);a[0][2] = rs.getString(4);a[0][3] = rs.getString(5);a[0][4] = rs.getString(6);a[0][5] = rs.getString(7);a[0][6] = rs.getString(8);a[0][7] = rs.getString(9);table.repaint();}con.close();} catch (SQLException e1) {System.out.println(e1);}if (e.getSource() == entermodify)try {con = DriverManager.getConnection("jdbc:mysql://localhost:3306/administration", "root","123");sql = con.createStatement();sql.executeUpdate("UPDATE message SET name='" + a[0][0]+ "',class_1='" + a[0][1] + "',birthday='" + a[0][2]+ "',english='" + a[0][3] + "'" + ",java1='" + a[0][4]+ "',probabilism='" + a[0][5] + "',network='" + a[0][6]+ "',graphtheory='" + a[0][7] + "'where xuehao='" + num+ "'");JOptionPane.showMessageDialog(this, "更新成功", "成功",JOptionPane.PLAIN_MESSAGE);con.close();} catch (SQLException e2) {JOptionPane.showMessageDialog(this, "更新失败" + e2, "失败",JOptionPane.ERROR_MESSAGE);}}//单个查询xiugai1() {Toolkit kit = Toolkit.getDefaultToolkit();Image img = kit.getImage("tupian.jpg");frame.setIconImage(img);hintLabel = new JLabel("输入学号:(回车确认)");inputNumber = new JTextField(20);table = new JTable(a, name1);entermodify = new JButton("更新记录");setLayout(null);Box baseBox = Box.createHorizontalBox();baseBox.add(hintLabel);baseBox.add(inputNumber);baseBox.add(new JScrollPane(table));baseBox.add(entermodify);add(baseBox);baseBox.setBounds(10, 20, 600, 38);inputNumber.addActionListener(this);entermodify.addActionListener(this);setBounds(20, 60, 700, 200);setVisible(true);validate();}public void actionPerformed(ActionEvent e) { if (e.getSource() == inputNumber)try {num = inputNumber.getText().trim();con = DriverManager.getConnection("jdbc:mysql://localhost:3306/administration", "root","123");sql = con.createStatement();rs = sql.executeQuery("select*from message where xuehao='"+ num + "'");boolean boo = rs.next();if (boo == false) {JOptionPane.showMessageDialog(this, "学号不存在", "提示", JOptionPane.WARNING_MESSAGE);} else {a[0][0] = rs.getString(2);a[0][1] = rs.getString(3);a[0][2] = rs.getString(4);a[0][3] = rs.getString(5);a[0][4] = rs.getString(6);a[0][5] = rs.getString(7);a[0][6] = rs.getString(8);a[0][7] = rs.getString(9);table.repaint();}con.close();} catch (SQLException e1) {System.out.println(e1);}if (e.getSource() == entermodify)try {con = DriverManager.getConnection("jdbc:mysql://localhost:3306/administration", "root","123");sql = con.createStatement();sql.executeUpdate("UPDATE message SET name='" + a[0][0]+ "',class_1='" + a[0][1] + "',birthday='" + a[0][2]+ "',english='" + a[0][3] + "'" + ",java1='" + a[0][4]+ "',probabilism='" + a[0][5] + "',network='" + a[0][6]+ "',graphtheory='" + a[0][7] + "'where xuehao='" + num+ "'");JOptionPane.showMessageDialog(this, "更新成功", "成功",JOptionPane.PLAIN_MESSAGE);con.close();} catch (SQLException e2) {JOptionPane.showMessageDialog(this, "更新失败" + e2, "失败",JOptionPane.ERROR_MESSAGE);}}//查询所有findAllRecord() {showRecord = new JButton("查询所有");showRecord.addActionListener(this);add(showRecord, BorderLayout.NORTH);setBounds(200, 60, 400, 250);setVisible(true);validate();}public void actionPerformed(ActionEvent e) {try {Class.forName("com.mysql.jdbc.Driver");} catch (ClassNotFoundException eee) {System.out.println("" + eee);}try {con = DriverManager.getConnection("jdbc:mysql://localhost:3306/administration","root", "123");sql = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);rs = sql.executeQuery("SELECT*FROM message");st();int lastXuehao = rs.getRow();a = new Object[lastXuehao][9];int k = 0;rs.beforeFirst();while (rs.next()) {a[k][0] = rs.getInt(1);a[k][1] = rs.getString(2);a[k][2] = rs.getString(3);a[k][3] = rs.getString(4);a[k][4] = rs.getString(5);a[k][5] = rs.getString(6);a[k][6] = rs.getString(7);a[k][7] = rs.getString(8);a[k][8] = rs.getString(9);k++;}con.close();} catch (SQLException e1) {System.out.println(e1);}table = new JTable(a, name);getContentPane().removeAll();add(showRecord, BorderLayout.NORTH);add(new JScrollPane(table), BorderLayout.CENTER);validate();}//登录界面denglu() {Toolkit kit = Toolkit.getDefaultToolkit();Image img = kit.getImage("zhuye.jpg");frame.setIconImage(img);button1 = new Button("登陆");button2 = new Button("退出");Panel p1 = new Panel();l1 = new Label("学生成绩管理系统", Label.CENTER);l1.setFont(new Font("隶书", Font.BOLD, 50));l1.setBackground(Color.cyan);p1.add(l1);l2 = new Label("登录名");l3 = new Label("密码");a1 = new TextField(10);a2 = new TextField(10);a2.setEchoChar('*');b1 = Box.createVerticalBox();b1.add(l2);b1.add(Box.createVerticalStrut(8));b1.add(l3);b2 = Box.createVerticalBox();b2.add(a1);b2.add(Box.createVerticalStrut(8));b2.add(a2);b3 = Box.createHorizontalBox();b3.add(b1);b3.add(Box.createHorizontalStrut(10));b3.add(b2);b4 = Box.createHorizontalBox();b4.add(button1);b4.add(Box.createHorizontalStrut(10));b4.add(button2);b5 = Box.createVerticalBox();b5.add(b3);b5.add(Box.createVerticalStrut(8));b5.add(b4);button1.addActionListener(this);button2.addActionListener(this);a1.setText("lml");a2.setText("1104991114");addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose();}bg = new ImageIcon("zhuye.jpg");JLabel label = new JLabel(bg);label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());imagePanel = (JPanel) frame.getContentPane();imagePanel.setOpaque(false);imagePanel.setLayout(new FlowLayout());imagePanel.add(p1, BorderLayout.NORTH);imagePanel.add(b5, BorderLayout.CENTER);frame.getLayeredPane().setLayout(null);frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(bg.getIconWidth(), bg.getIconHeight());frame.setBounds(200, 150, bg.getIconWidth(), bg.getIconHeight());frame.setResizable(true);// 设置窗口大小不可改变frame.setVisible(true);validate();}public void actionPerformed(ActionEvent e) {if (e.getSource() == button2) {System.exit(0);}if (e.getSource() == button1) {if(a1.getText().equals("lml") && a2.getText().equals("1104991114")) {new chuangkou1();frame.dispose();} else {JOptionPane.showMessageDialog(this, "账户密码错误,请重新输入!");。