图书管理系统---java代码

更新时间:2023-07-01 11:50:33 阅读: 评论:0

import java.awt。*;
import java.awt.event。*;
import java.sql.*;
import java。util。*;
import javax.swing。*;
// ———-———--——————-———--——-——-———--——--—-—-—--——--———-—————--———--————-—-————————-——---———-————-—-—-—————--—
class Tsgl {
    public static void main(String args[]) {
dbframe db = new dbframe(”图书管理程序”);
    }
// 图书管理系统主界面
class dbframe extends Frame implements ActionListener {
    MenuBar daohang = new MenuBar(); // 建立菜单栏
    Menu mfile = new Menu(”功能"); // 建立“功能”菜单组
    Menu mhelp = new Menu(”帮助"); // 建立“帮助”菜单组
    MenuItem mdenglu = new MenuItem(”登陆”);
    MenuItem mchaxun = new MenuItem("查询");
    MenuItem mtianjia = new MenuItem(”添加");
    MenuItem mshanchu = new MenuItem("删除");
    MenuItem mexit = new MenuItem("退出");
    MenuItem mhelpp = new MenuItem(”关于");
    Denglu pdenglu=new Denglu();
    Ptianjia ptianjia = new Ptianjia();
    Pmain pmain = new Pmain();
    Pchaxun pchaxun = new Pchaxun();
    Pshanchu pshanchu = new Pshanchu();
    dbframe(String s) { // 在窗口上添加菜单选项
        tTitle(s);
        mfile。add(mdenglu);
        mfile.add(mtianjia);
        mfile。add(mchaxun);
        mfile。add(mshanchu);
        mfile。add(mexit);
五彩蝴蝶
        mhelp。add(mhelpp);
        daohang。add(mfile);
        daohang.add(mhelp);
        tMenuBar(daohang);
        add(pmain);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                it(0);
            }
        });
        tBounds(200, 200, 340, 250);
        tResizable(fal);
        tVisible(true);
        mexit.addActionListener(this);
        mdenglu.addActionListener(this);
        mtianjia.addActionListener(this);
        mchaxun.addActionListener(this);
        mshanchu。addActionListener(this);
        mhelpp。addActionListener(this);
老舍的茶馆
        validate();
    } // 窗口事件监听
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == mexit)
            it(0);
        if(e。getSource()==mdenglu){
            removeAll();
            add(pdenglu);
            validate();
        }
        if (e。getSource() == mtianjia) {
            removeAll();
            add(ptianjia);
            validate();
        } // 图书添加功能
        if (e。getSource() == mchaxun) {
            removeAll();
            add(pchaxun);
            validate();
        } // 图书查询功能
        if (e。getSource() == mshanchu) {
            removeAll();
            add(pshanchu);
            validate();
        } // 图书删除功能
        if (e。getSource() == mhelpp) {纵横之术
            JOptionPane。showMessageDialog(this, ”欢迎使用图书管理系统”, ”关于本系统”,
                    JOptionPane。INFORMATION_MESSAGE);
        }
    } // 各功能菜单事件监听
//
class Ptianjia extends Panel implements ActionListener {
    TextField tname, tauthor, tpublish, tdate, tcomment;
    Label lname, lauthor, lpublish, ldate, lcomment;
    Button btn;
    Ptianjia() {
        tLayout(null);
        btn = new Button("添加"); // 创建“添加”按钮
        tname = new TextField();
        tauthor = new TextField();
        tpublish = new TextField();
        tdate = new TextField();
        tcomment = new TextField(); // 创建5个文本框
        lname = new Label(”书名”);
        lauthor = new Label("作者”);
        lpublish = new Label(”出版社”);
        ldate = new Label(”出版日期");
        lcomment = new Label("评论");
        add(lname);
        add(tname);
add(lauthor);
        add(tauthor);好词有哪些
        add(lpublish);
        add(tpublish);
        add(ldate);长相思林逋
展喜        add(tdate);
        add(lcomment);
        add(tcomment);
        add(btn); // 添加“按钮"到窗口面板上
        lname.tBounds(10, 10, 70, 25);
        tname。tBounds(90, 10, 220, 25);
        lauthor.tBounds(10, 40, 70, 25);
        tauthor.tBounds(90, 40, 220, 25);
        lpublish.tBounds(10, 70, 70, 25);
        tpublish。tBounds(90, 70, 220, 25);
        ldate.tBounds(10, 100, 70, 25);
        tdate。tBounds(90, 100, 220, 25);
        lcomment。tBounds(10, 130, 70, 25);
        tcomment。tBounds(90, 130, 220, 25);
btn.tBounds(130, 160, 70, 25); // 设置按钮位置
        btn。addActionListener(this); // 设置按钮监听
        tSize(340, 250); // 设置窗口大小
樊江
        tBackground(Color。white); // 设置窗口背景颜色
        tVisible(true);
        validate();
    }
    public void actionPerformed(ActionEvent e) {
        String sname = Text();
        String sauthor = tauthor。getText();
        String spublish = tpublish。getText();
        String sdate = Text();
        String scomment = tcomment。getText();
        String inrtstr = ”inrt into book  values" + "(” + "'” + sname + "’”
                + ”,” + "'” + sauthor + ”’" + "," + "'" + spublish + ”'" + ”,”
+ "'" + sdate + "’” + ”,” + ”’” + scomment + ”’” + ”)”; // SQL语句
        Connection con;
        Statement sta;
        ResultSet rs;
        try {
            Class.forName(”oracle。jdbc。driver。OracleDriver”); // 加载JDBC驱动
        } catch (ClassNotFoundException ee) {
            System.out.println(”” + ee);
        }
支付安全
        try {
            con = Connection(”jdbc:oracle:thin:@localhost:1521:orcl”, ”sa”, ”orcl”); // 连接数据库
            sta = ateStatement();
            sta。executeUpdate(inrtstr); // 执行SQL语句
            con。clo(); // 关闭数据库
            tname。tText("”);
            tauthor。tText(””);
            tpublish。tText(””);
            tdate。tText("");
            tcomment。tText("”); // 重新初始化文本框内容

本文发布于:2023-07-01 11:50:33,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1063082.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:图书   功能   按钮   菜单   添加   设置
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图