团队作业(五):冲刺总结5
项目名:电子公文传输系统
成员分工:熊悠越(前端开发)、罗杰逊+谷丰宇(后端开发)、陈夏林(数据库管理)、董准(系统测试与维护)
日期:2023.12.12
今日任务完成情况
前端部分代码
管理员登录系统
/*adminLogin.java*/
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class adminLogin extends JFrame implements ActionListener
{
private JPasswordField mima1 = new JPasswordField(30); // 创建文本行组件, 30 列
private JTextField zh1 = new JTextField(30);
private JButton dl1 = new JButton("登陆");
private JButton zb1 = new JButton("注册账号");
private JLabel zh2 = new JLabel("账号:");
private JLabel mima2 = new JLabel("密码:");
private static String serverFilePath = "C:\\Users\\14914\\Desktop\\test";
private static String clientFilePath = "C:\\Users\\14914\\Desktop\\clienttest";
BackgroundPanel bgp;
JFrame f;
String st5 = "1";
String st6 = "0";
public void Serverframe(){
//显示信息提示框
JFrame frame1 = new JFrame("server resources");
frame1.setBounds(820, 150, 600, 400);
frame1.setLayout(null);
Vector rowData = PutinStorage.getRows();
// 取得haha数据库的aa表的表头数据
Vector columnNames = PutinStorage.getHead();
DefaultTableModel tableModel = new DefaultTableModel(rowData, columnNames);
JTable table1 = new JTable(tableModel);
JPanel panelUP1 = new JPanel(); // 新建按钮组件面板
JScrollPane s1 = new JScrollPane(table1);
s1.setBounds(10, 10, 450, 600);
//panelUP.setBounds(5,70,320,550);
// 将面板和表格分别添加到窗体中
frame1.add(panelUP1);
frame1.add(s1);
JButton download1 = new JButton("remove");
download1.setBounds(470, 50, 90, 30);
frame1.add(download1);
JButton exit1 = new JButton("exit");
exit1.setBounds(470, 250, 90, 30);
frame1.add(exit1);
exit1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
frame1.dispose();
}
});
download1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
int rowcount = table1.getSelectedRow();
int column = table1.getColumnCount(); // 表格列数
int row = table1.getRowCount(); // 表格行数
// value数组存放表格中的所有数据
String[][] value = new String[row][column];
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
value[i][j] = table1.getValueAt(i, j).toString().trim();
}
}
String serverfilename = serverFilePath + "\\" + value[rowcount][0];
new fileaddsql().fileRremove(serverfilename);
File file = new File(serverfilename);
file.delete();
JOptionPane.showMessageDialog(null, "删除成功");
frame1.dispose();
Serverframe();
}
});
frame1.setVisible(true);
frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public adminLogin()
{
f = new JFrame("登陆界面");
f.setBounds(200, 150, 555, 420);
f.setLayout(null);
bgp=new BackgroundPanel((new ImageIcon("C:\\Users\\14914\\Desktop\\图片中转站\\背景\\2.jpg")).getImage());
bgp.setBounds(0,0,555,188);
zh1.setBounds(120, 190, 300, 40);
mima1.setBounds(120, 238, 300, 40);
dl1.setBounds(120, 300, 300, 46);
zh2.setBounds(70, 190, 50, 40);
zb1.setBounds(0, 350, 90, 25);
mima2.setBounds(70, 238, 50, 40);
// 把组件添加进窗口f中
f.add(mima1);
f.add(zh1);
f.add(dl1);
f.add(zb1);
f.add(zh2);
f.add(mima2);
f.add(bgp);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
KeyListener key_Listener = new KeyListener()
{
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e){}
public void keyPressed(KeyEvent e){
if(e.getKeyChar() == KeyEvent.VK_ENTER )
{
PreparedStatement ps=null;
Connection ct=null;
ResultSet rs=null;
String st1 = "null";
{
try {
//1.加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//2.得到链接 127.0.0.1:1433
ct=DriverManager.getConnection
("jdbc:mysql://127.0.0.1:3307/myfiletra?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8","root","123456");
String sql="select password from manager where id = ?";
ps=ct.prepareStatement(sql);
//给?赋值
ps.setString(1, zh1.getText());
rs=ps.executeQuery();
while(rs.next()){
st1=rs.getString(1).trim();
}
}catch(Exception d) {
d.printStackTrace();
}finally {
try {
if(rs!=null)rs.close();
if(ps!=null)ps.close();
if(ct!=null)ct.close();
}catch(Exception d) {
d.printStackTrace();
}
}
if(st1.equals(String.valueOf(mima1.getPassword())))
{
f.setVisible(false);
JOptionPane.showMessageDialog(null, "登录成功,欢迎到来!");
Serverframe();
}
else
{
JOptionPane.showMessageDialog(null, "用户或密码错误!请从新登录!");
//显示信息提示框
zh1.setText("");
mima1.setText("");
}
}
}
}
};
mima1.addKeyListener(key_Listener);
dl1.addActionListener(this); //登录增加事件监听
this.pack(); //表示随着面板自动调整大小
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent q) //
{
if(q.getSource() == dl1) {
PreparedStatement ps = null;
Connection ct = null;
ResultSet rs = null;
String st1 = "null";
try {
//1.加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//2.得到链接 127.0.0.1:1433
ct = DriverManager.getConnection
("jdbc:mysql://127.0.0.1:3307/myfiletra?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8","root","123456");
String sql = "select id from manager where id = ?";
ps = ct.prepareStatement(sql);
//给?赋值
ps.setString(1, zh1.getText());
rs = ps.executeQuery();
while (rs.next()) {
st1 = rs.getString(1).trim();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null) rs.close();
if (ps != null) ps.close();
if (ct != null) ct.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if(st1.equals(String.valueOf(mima1.getPassword())))
{
f.setVisible(false);
JOptionPane.showMessageDialog(null, "登录成功,欢迎到来!");
//显示信息提示框
(new FileTree()).show(true);;
}
else
{
JOptionPane.showMessageDialog(null, "用户或密码错误!请从新登录!");
//显示信息提示框
zh1.setText("");
mima1.setText("");
}
}
}
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new adminLogin();
}
}
使用 Java Swing 库创建的简单图形用户界面
/*Text.java*/
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame
{
//创建一个容器
Container ct;
//创建背景面板。
BackgroundPanel bgp;
//创建一个按钮,用来证明我们的确是创建了背景图片,而不是一张图片。
JButton jb;
public static void main(String[] args)
{
new Test();
}
public Test()
{
//不采用任何布局方式。
ct=this.getContentPane();
this.setLayout(null);
//在这里随便找一张400*300的照片既可以看到测试结果。
bgp=new BackgroundPanel((new ImageIcon("C:\\Users\\14914\\Pictures\\background.jpg")).getImage());
bgp.setBounds(0,0,400,300);
ct.add(bgp);
//创建按钮
jb=new JButton("测试按钮");
jb.setBounds(60,30,160,30);
ct.add(jb);
this.setSize(400,300);
this.setLocation(400,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
class BackgroundPanel extends JPanel
{
Image im;
public BackgroundPanel(Image im)
{
this.im=im;
this.setOpaque(true);
}
//Draw the back ground.
public void paintComponent(Graphics g)
{
super.paintComponents(g);
g.drawImage(im,0,0,this.getWidth(),this.getHeight(),this);
}
}
后端部分代码
监听客户端的连接请求,接收文件下载请求,并将文件数据传输给连接的客户端
import javax.xml.crypto.Data;
import java.io.*;
import java.net.*;
public class FileServer extends Thread{
private static Socket s;
private static ServerSocket serverSocket;
private File source = new File("C:\\Users\\14914\\Desktop\\test\\moren55.txt");//服务端显示文件的存放位置
static ServerSocket server;
//6788端口负责向客户端发送文件
static {
try {
server = new ServerSocket(6788);
} catch (IOException e) {
e.printStackTrace();
}
}
public FileServer(Socket s, File source) throws IOException {
super();
this.s = s;
this.source = source;
}
/**
* 获取想要客户端下载的目标文件的文件名
* @param s
* @return
* @throws IOException
*/
public static String getfilepath(Socket s) throws IOException {
String name = null;
InputStream is = null;
try {
//读取文件名
is = s.getInputStream();
int len1;
byte[] bs = new byte[1024];
len1 = is.read(bs);
name = new String(bs, 0, len1);
} catch (IOException e) {
e.printStackTrace();
}
return name;
}
@Override
public void run() {
DataInputStream bis = null;
DataOutputStream bos = null;
try {
// //获取源文件的输入流
System.out.println(source.getAbsolutePath());
bis = new DataInputStream(new FileInputStream(source));
//获取socket的输出流并包装
Socket s = server.accept();
bos = new DataOutputStream(s.getOutputStream());
byte[] b = new byte[1027 * 9];
int len = 0;
System.out.println("向 " + s.getInetAddress().getHostAddress() + "开始传输....");
while ((len = bis.read(b)) != -1) {
bos.write(b, 0, len);
}
System.out.println("向 " + s.getInetAddress().getHostAddress() + "传输完成!");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bos != null) bos.flush();bos.close();
if (bis != null) bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void netStartServer() throws IOException {
System.out.println("SOFEEM文件服务器已启动,等待连接...");
//循环监听是否有客户端上传到服务器文件
new FileTransferServer().start();
while(true){
File source = new File(new FileTree().serverfilename);
Socket s = server.accept();
System.out.println(s.getInetAddress().getHostAddress()+"进入服务器,准备传输...");
source = new File(getfilepath(s));
//根据每一个连接的客户端启动一条子线程
new FileServer(s, source).start();
}
}
public static void main(String[] args) throws IOException {
System.out.println("SOFEEM文件服务器已启动,等待连接...");
//循环监听是否有客户端上传到服务器文件
new FileTransferServer().start();
while(true){
File source = new File(new FileTree().serverfilename);
Socket s = server.accept();
System.out.println(s.getInetAddress().getHostAddress()+"进入服务器,准备传输...");
source = new File(getfilepath(s));
//根据每一个连接的客户端启动一条子线程
new FileServer(s, source).start();
}
}
}
以上代码均已托管至公文传输系统实现代码/冲刺
冲刺第五天
| 第五天 | 负责人 | 工作量 |
|---|---|---|
| 调试数据库 | 陈夏林 | 4 |
| 完善数据库初始化设置 | 陈夏林 | 2 |
| 加解密功能实现 | 谷丰宇、罗杰逊 | 2 |
| 主干功能模块化并测试 | 谷丰宇、罗杰逊 | 3 |
| 功能测试 | 董准 | 2 |
| 完善文件上传下载模块 | 谷丰宇、罗杰逊 | 1 |
| 适配增加的功能 | 谷丰宇、罗杰逊 | 1 |
| 风格化样式 | 董准、熊悠越 | 2 |
| 根据后端接口完善前端界面 | 董准、熊悠越 | 2 |
| 继续完善用户数据的相关内容 | 董准、熊悠越 | 2 |
| 明日任务安排 | 罗杰逊 | 1 |
明日任务安排
| 第六天 | 工作量 |
|---|---|
| 继续调试数据库 | 2 |
| 加解密功能实现 | 4 |
| 前后端优化匹配 | 4 |
| 主干功能模块化并测试 | 4 |
| 接口调试 | 2 |
| 适配增加的功能 | 1 |
| 前后端优化匹配 | 4 |
| 风格化样式 | 3 |
| 根据后端接口完善前端界面 | 3 |
| 继续完善用户数据的相关内容 | 2 |