| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 677 人关注过本帖
标题:图书查询系统
只看楼主 加入收藏
我是小小草
Rank: 1
等 级:新手上路
帖 子:14
专家分:2
注 册:2009-8-6
结帖率:100%
收藏
 问题点数:0 回复次数:0 
图书查询系统
    图书查询系统
要求完成:
(1)    图书信息的添加、删除、查询、修改功能
(2)    使用界面操作
(3)    使用文件完成
下面是写的程序,删除和修改不会写,请高手指导。
急用,在线等。
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import
import
import
import
import
import
import
import
import java.util.StringTokenizer;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
class Lab extends JFrame{
    private String shuming;
    private String shuhao;
    private String chubanshe;
    JLabel b1=new JLabel("信息管理");
    JTextField 书名,书号,出版社;
    JButton 添加,查找,删除,修改,重置;
    JPanel p1,p2,p3,p4,p5,p6;
    public Lab()
    {
        书名=new JTextField(10);
        书号=new JTextField(10);
        出版社=new JTextField(10);
        添加=new JButton("添加");
        查找=new JButton("查找");
        删除=new JButton("删除");
        修改=new JButton("修改");
        重置=new JButton("重置");
        p1=new JPanel();
        p1.add(b1);
        p2=new JPanel();
        p2.add(new JLabel("书名:",JLabel.CENTER));
        p2.add(书名);
        p3=new JPanel();
        p3.add(new JLabel("书号:",JLabel.CENTER));
        p3.add(书号);
        p4=new JPanel();
        p4.add(new JLabel("出版社:",JLabel.CENTER));
        p4.add(出版社);
        p5=new JPanel();
        p5.add(添加);
        添加.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                PrintWriter t=null;               
                try {
                    
                    String shuming="";
                    shuming=书名.getText();
                    String shuhao="";
                    shuhao=书号.getText();
                    String chubanshe="";
                    chubanshe=出版社.getText();
                    t= new PrintWriter(new FileWriter("labria.txt",true));
                    t.println(shuming+"|"+shuhao+"|"+chubanshe);
                } catch (FileNotFoundException e1) {
                    
                } catch (IOException e2) {
                    
                }
                t.close();
               
            }
        });
        p5.add(查找);
        查找.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                BufferedReader bf=null;               
                String shuhao=书号.getText();               
                try {
                    bf=new BufferedReader(new FileReader("labria.txt"));
                    String read;
                    int bl = 0;
                    while((read=bf.readLine())!=null){
                        StringTokenizer st=new StringTokenizer(read,"|");
                        String shumi=st.nextToken();
                        String shuh=st.nextToken();
                        String chuban=st.nextToken();
                        if(shuh.equals(shuhao)){
                            JOptionPane.showMessageDialog(null, "书名:" + shumi+ "\n书号:" + shuh+"\n出版社:"+chuban);

                            System.out.println(read);
                            bl=0;
                        }
                        else{
                            bl=1;
                        }
                    }
                    if(bl==1){
                        JOptionPane.showMessageDialog(null, "找不到信息");
                    }
                    bf.close();
                } catch (FileNotFoundException e1) {
                    
                } catch (IOException e1) {
                    
                }
            }
        });
        p5.add(删除);
        删除.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                BufferedReader bf=null;
                BufferedWriter ra=null;
                String shuming=书名.getText();
               
                //String shuhao=书号.getText();
               
                //String chubanshe=出版社.getText();
                //String temp=shuming+"|"+shuhao+"|"+chubanshe;
                try {
                    ra=new BufferedWriter(new FileWriter("labria.txt"));
                    bf=new BufferedReader(new FileReader("labria.txt"));
                    String read,rea;
                    int bl = 0;
                    StringBuffer re=new StringBuffer();
                    while((read=bf.readLine())!=null){
                        StringTokenizer st=new StringTokenizer(read,"|");
                        String shumi=st.nextToken();
                        //String shuh=st.nextToken();
                        //String chuban=st.nextToken();
                        if(shumi.equals(shuming)){
                            re.append(read+"\n");
                            rea=re.toString();
                            bf.close();
                            rea=rea.replaceAll(read, "");
                            //JOptionPane.showMessageDialog(null, "书名:" + shumi+ "\n书号:" + shuh+"\n出版社:"+chuban);
                            //read="";
                            //bf.reset();
                            //String rea=bf.readLine();
                            //rea="bbb";
                            //ra.write(read);
                            //bl=0;
                        }
                        else{
                            bl=1;
                        }
                    }
                    
                    if(bl==1){
                        JOptionPane.showMessageDialog(null, "找不到信息");
                    }
                    bf.close();
                } catch (FileNotFoundException e1) {
                    
                } catch (IOException e1) {
                    
                }
            }
        });
        p5.add(修改);
        修改.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
            书名.setText("");
            书号.setText("");
            出版社.setText("");
            }
            });
        p5.add(重置);
        重置.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
            书名.setText("");
            书号.setText("");
            出版社.setText("");
            }
            });
        p6=new JPanel();
        p6.setLayout(new GridLayout(5,1));
        p6.add(p1);
        p6.add(p2);
        p6.add(p3);
        p6.add(p4);
        p6.add(p5);
        JFrame jf=new JFrame("图书管理系统");
        jf.setBounds(200,200,400,500);
        jf.setVisible(true);
        jf.add(p6);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }   
    public String getChubanshe() {
        return chubanshe;
    }
    public void setChubanshe(String chubanshe) {
        this.chubanshe = chubanshe;
    }
    public String getShuhao() {
        return shuhao;
    }
    public void setShuhao(String shuhao) {
        this.shuhao = shuhao;
    }
    public String getShuming() {
        return shuming;
    }
    public void setShuming(String shuming) {
        this.shuming = shuming;
    }   
}

public class Labri{
    public static void main(String[] args){
        Lab l=new Lab();
    }
}
搜索更多相关主题的帖子: 图书 系统 查询 
2010-07-06 13:07
快速回复:图书查询系统
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021268 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved