资源描述
超市信息管理系统设计文档
姓名 葛晓瑜 学号 1220126327 班级 软件1213
一、用户登录界面:PassWordFrame类
用户名:1220126327
密码:gexiaoyu
二、 主界面:MarketFrame类
三、 信息的增删查改:InfoMag类
//查找功能
private int itemSearch(){
findItem = findField.getText();
int row = table.getRowCount();
int i;
for(i = 0 ; i < row ; i++){
if(findItem.equals((String)table.getValueAt(i,1))){
toID = (String)table.getValueAt(i,0);
toName = (String)table.getValueAt(i,1);
toMuch = (String)table.getValueAt(i,2);
toMenuf = (String)table.getValueAt(i,3);
toMenufTel = (String)table.getValueAt(i,4);
break;
}
else
continue;
}
if(i>=row){
return -1;
}
return i;
}
//增加一行
private void addRow(){
Object[] a ={"输入框","输入框","输入框","输入框","输入框"};
tableModel.addRow(a);//增加一行
isChange = true;
}
//插入一行
private void insertRow(){
Object[] a ={"输入框","输入框","输入框","输入框","输入框"};
int select=table.getSelectedRow();
tableModel.insertRow(select+1,a);
}
//删除一行
private void delRow(){
int rowNumNow = table.getSelectedRow();//得到当前光标所在行
if(rowNumNow != -1)
tableModel.removeRow(rowNumNow);//删除
}
四、 信息的保存读出:ProductInfo类、ProInfo类、InfoMag类
ProductInfo类: 主要实现了JTable中的录入的商品信息在文件
ProInfo类: 主要定义了一些商品的信息,如:编号、名称、售价,供货商以及联系方式,并将该信息进行写入读出的操作。
InfoMag类: 部分文件的读取保存
//初始化读取文件
public void fileRead()throws IOException,ClassNotFoundException{
fileName = new File("./classes/file/product.tan");
if(fileName.length() != 0)
{
FileInputStream fileInStream = new FileInputStream(fileName);
ObjectInputStream objectInStream = new ObjectInputStream(fileInStream);
ProInfo pInfo =new ProInfo();
int row = 0;
try{
while(true){
pInfo = (ProInfo)objectInStream.readObject();
table.setValueAt(pInfo.proID,row,0);
table.setValueAt(pInfo.proName,row,1);
table.setValueAt(pInfo.proMuch,row,2);
table.setValueAt(pInfo.proMenuf,row,3);
table.setValueAt(pInfo.proMenufTel,row,4);
row++;
addRow();
}
}catch(EOFException e){
}
//文件结束以抛出EOFException异常
tableModel.removeRow(row);
objectInStream.close();
}
}
//保存文件
private void fileSave()throws IOException{
fileName = new File("./classes/file/product.tan");
FileOutputStream fileOutStream = new FileOutputStream(fileName);
ObjectOutputStream objOutStream = new ObjectOutputStream(fileOutStream);
rowNum = table.getRowCount();
colNum = table.getColumnCount();
for(int i = 0 ; i < rowNum ; i++){
pID = (String)table.getValueAt(i,0);
pName = (String)table.getValueAt(i,1);
pMuch = (String)table.getValueAt(i,2);
pMenuf = (String)table.getValueAt(i,3);
pMenufTel = (String)table.getValueAt(i,4);
if(pID.equals("输入框") || pID == null)
break;
ProInfo info = new ProInfo(pID,pName,pMuch,pMenuf,pMenufTel);
try{
objOutStream.writeObject(info);
}catch(IOException er){
}
}
isChange = false;
objOutStream.close();
MarketFrame.mutex = true;
}
五、 简单的帮助:InfoMag类
帮助文件中详细了各个按钮的功能,简单易懂。
六、 个人感想:
本次大作业由本人一人完成,程序中还有很多小的问题,有些方面比如集合类框架没有熟练掌握,但是通过这次作业,让我锻炼了编程能力,让我更加了解到java语言的魅力所在!
展开阅读全文