目录
1.团队课程设计博客链接
团队博客:https://www.cnblogs.com/zhonghaiqing/p/12173066.html
2.个人负责模块或任务说明
我主要负责主要负责管理员类,实现滚动抽奖、自动注册购买彩票以及查看中奖信息和用户信息的方法
3.自己的代码提交记录截图
4.自己负责模块或任务详细说明
滚动抽奖
- 代码
public class MyThread extends Thread{//使用Runnable实现多线程可以达到资源共享目的
JTextField jf;
public volatile Boolean isPause=true;//暂停标志
public MyThread(JTextField jf) {
super();
this.jf = jf;
}
@Override
public void run() {
while(true){
try {
MyThread.sleep(100);
}catch(InterruptedException e) {
e.printStackTrace();
}
while(isPause) {
int[] ball = new int[7];
for(int i = 0;i<7;i++) {
ball[i] = (int) (1+(Math.random()*36));
for(int j=0;j<i;j++) {
if(ball[i]==ball[j]) i--;//随机产生不重复的七个数字
}
}
Arrays.sort(ball);
jf.setText(ball[0]+","+ball[1]+","+ball[2]+","+ball[3]+","+ball[4]+","+ball[5]+","+ball[6]);
}
}
}
public void stopping() {
isPause=false;
}
}
- 详解
自动注册
- 代码
public void Auto_Register(UAndT uat) throws IOException {
String nikename = generateString();
String name = generateString();
String password = generateString();
Random random = new Random();
int balance = random.nextInt(100);
String phone = generatePhoneString();
User newUsers = new User(nikename, name, phone, password, balance); // 注册账户
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String pool = generateNumber();// 随机号码
int multiple = random.nextInt(1000);
Tickets ticket = new Tickets();
ticket.setNumber(pool);
ticket.setAmount(multiple);
uat.buyTickets(newUsers, ticket);
String filename = "txt\\UAndT.txt";
//int r = countLines(filename);
try (BufferedWriter bw = new BufferedWriter(new FileWriter(filename, true))) {
bw.write(dateFormat.format(date));
bw.write(" ");
bw.write(newUsers.getName());
bw.write(" ");
bw.write(pool);
//bw.write(UserGui.getUtlist().get(r).getTicket().getNumber());
bw.write(" ");
bw.write(Integer.toString(multiple));
bw.write(" ");
bw.newLine();
bw.flush();
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
newUsers.register();
}
public void AutoRegister(String string) {
UAndT uat = new UAndT();
int num = Integer.parseInt(string);
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
for (int i = 0; i < num; i++) {
try {
Auto_Register(uat);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// UserGui.getUtlist().add(uat);
}
}
});
t1.start();
}
- 详解
读取表格信息
- 代码
// 历史开奖
private Vector<Vector<String>> createTableModelData_historyAward() {
Vector<Vector<String>> data = new Vector<Vector<String>>();
String t = null;
try {
FileReader fr1 = null;
try {
String fileName = "txt/History.txt";
fr1 = new FileReader(fileName);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader br = new BufferedReader(fr1);
while ((t = br.readLine()) != null) {
String[] s = t.split("\\s+"); // 通过空格分割字符串数组
Vector<String> rowData = new Vector<String>();
// rowData.add("i");
String temp = s[0] + " " + s[1];
// rowData.add(s[0]);
rowData.add(temp);
rowData.add(s[2]);
rowData.add(s[3]);
rowData.add(s[4]);
rowData.add(s[5]);
data.add(rowData);
}
fr1.close();
br.close();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return data;
}
private Vector<String> createColumnNames_historyAward() {
Vector<String> columnNames = new Vector<String>();
// columnNames.add("序号");
columnNames.add("日期");
columnNames.add("号码");
columnNames.add("奖池");
columnNames.add("用户名");
columnNames.add("中奖金额");
return columnNames;
}
public DefaultTableModel historyAward() {
DefaultTableModel model = null;
// 表头(列名)
Vector<String> columnNames = createColumnNames_historyAward();
Vector<Vector<String>> data = createTableModelData_historyAward();
// 创建一个默认的表格模型
model = new DefaultTableModel(data, columnNames);
return model;
}
- 详解
5.课程设计感想
学习要在实践中摸索才有实际成效,在编写函数的同时也提升了查找关键字的能力。这次课设可以实现学生信息的增删改查、对单个学生各科成绩画出柱状分布图功能和将学生信息汇总成excel功能,但还未实现多名学生同时生成成绩对比图,柱状图的画面质感也有待改进。我们希望在暑假能进一步完善功能,做出真正能够投入使用的学生成绩管理系统。