⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookupdate.java~10~

📁 Java信息系统设计与开发实例(第二版)随书源代码.
💻 JAVA~10~
字号:
package bookmanager;

import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class bookUpdate extends JFrame {
 //定义结果集
  ResultSet rs;
//定义数据库操作对象
  private DBManager db =new DBManager();

  XYLayout xYLayout1 = new XYLayout();
  JLabel jLabel4 = new JLabel();
  JTextField jTextFieldpress = new JTextField();
  JTextField jTextFieldname = new JTextField();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel7 = new JLabel();
  JButton jButtondicision = new JButton();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel6 = new JLabel();
  JTextField jTextFieldauthor = new JTextField();
  JTextField jTextFieldcomment = new JTextField();
  JTextField jTextFieldpressdate = new JTextField();
  JTextField jTextFieldprice = new JTextField();
  JTextField jTextFieldaddress = new JTextField();
  JButton jButtonClear = new JButton();
  JLabel jLabel5 = new JLabel();
  JButton jButtonupdate = new JButton();
  JButton jButtonexit = new JButton();
  JLabel jLabel8 = new JLabel();

  public bookUpdate() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    bookUpdate bookUpdate = new bookUpdate();
  }
  private void jbInit() throws Exception {
    jLabel5.setText("出版日期");
    jLabel5.setFont(new java.awt.Font("Dialog", 0, 16));
     jButtonClear.setText("清空");
    jButtonClear.addMouseListener(new bookUpdate_jButtonClear_mouseAdapter(this));
    jButtonClear.setFont(new java.awt.Font("Dialog", 0, 16));
    jTextFieldaddress.setText("");
    jTextFieldaddress.setFont(new java.awt.Font("Dialog", 0, 16));
    jTextFieldprice.setText("");
    jTextFieldprice.setFont(new java.awt.Font("Dialog", 0, 16));
    jTextFieldpressdate.setText("");
    jTextFieldpressdate.setFont(new java.awt.Font("Dialog", 0, 16));
    jTextFieldcomment.setText("");
    jTextFieldcomment.setFont(new java.awt.Font("Dialog", 0, 16));
    jTextFieldauthor.setText("");
    jTextFieldauthor.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel6.setText("价格");
    jLabel6.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel2.setText("出版社");
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));
     jButtondicision.setText("确定");
    jButtondicision.addMouseListener(new bookUpdate_jButtondicision_mouseAdapter(this));
    jButtondicision.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel7.setText("备注");
    jLabel7.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel3.setText("作者");
    jLabel3.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel1.setText("名称");
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
    jTextFieldname.setText("");
    jTextFieldname.setFont(new java.awt.Font("Dialog", 0, 16));
    jTextFieldpress.setText("");
    jTextFieldpress.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel4.setText("地址");
    jLabel4.setFont(new java.awt.Font("Dialog", 0, 16));
    xYLayout1.setWidth(472);
    xYLayout1.setHeight(375);
    this.getContentPane().setLayout(xYLayout1);
    jButtonupdate.setText("更新");
    jButtonupdate.addMouseListener(new bookUpdate_jButtonupdate_mouseAdapter(this));
     jButtonupdate.setFont(new java.awt.Font("Dialog", 0, 16));
    jButtonexit.setText("退出");
    jButtonexit.addMouseListener(new borrowHistoryall_jButtonexit_mouseAdapter(this));
    jButtonexit.addMouseListener(new borrowHistoryall_jButtonexit_mouseAdapter(this));
    jButtonexit.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel8.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel8.setText("输入书名点击确定,将调出此书相关信息");
    this.getContentPane().add(jTextFieldname, new XYConstraints(226, 40, 131, 27));
    this.getContentPane().add(jLabel1, new XYConstraints(100, 44, 72, -1));
    this.getContentPane().add(jLabel8,  new XYConstraints(27, 8, 300, 25));
    this.getContentPane().add(jButtondicision, new XYConstraints(161, 321, -1, 28));
    this.getContentPane().add(jButtonClear, new XYConstraints(94, 321, 66, 28));
    this.getContentPane().add(jButtonupdate, new XYConstraints(227, 321, 74, 27));
    this.getContentPane().add(jButtonexit, new XYConstraints(301, 321, 75, 28));
    this.getContentPane().add(jTextFieldpress, new XYConstraints(226, 94, 132, 28));
    this.getContentPane().add(jLabel4, new XYConstraints(105, 171, 51, 21));
    this.getContentPane().add(jLabel3, new XYConstraints(105, 134, 57, 21));
    this.getContentPane().add(jLabel7, new XYConstraints(104, 289, 54, 20));
    this.getContentPane().add(jLabel6, new XYConstraints(105, 248, 62, 26));
    this.getContentPane().add(jTextFieldcomment, new XYConstraints(227, 286, 137, 23));
    this.getContentPane().add(jTextFieldpressdate, new XYConstraints(228, 202, 137, -1));
    this.getContentPane().add(jTextFieldprice, new XYConstraints(226, 249, 139, 27));
    this.getContentPane().add(jLabel5, new XYConstraints(103, 210, 98, -1));
    this.getContentPane().add(jLabel2, new XYConstraints(102, 98, 89, 21));
    this.getContentPane().add(jTextFieldauthor, new XYConstraints(228, 128, 133, 26));
    this.getContentPane().add(jTextFieldaddress, new XYConstraints(227, 162, 134, 27));
  }

  void jButtonexit_mouseClicked(MouseEvent e) {
       this.dispose();
  }
//清空所有文本框
  void jButtonClear_mouseClicked(MouseEvent e) {
    jTextFieldname.setText("");
    jTextFieldpress.setText("");
     jTextFieldauthor.setText("");
      jTextFieldaddress.setText("");
       jTextFieldpressdate.setText("");
        jTextFieldprice.setText("");
         jTextFieldcomment.setText("");

  }
//查询相关信息
  void jButtondicision_mouseClicked(MouseEvent e) {
    String strSQL ;
	//校验书名是否为空
		 if(jTextFieldname.getText().trim().equals(""))
	       {JOptionPane.showMessageDialog(null,"书名不许为空!");
	        return;}
    //生成sql操作语句,查询要更新的书是否存在,若存在将此书相关信息绑顶到窗体上,若不存在提示并返回
   strSQL="select * from Books where bookname='"+jTextFieldname.getText().trim() +"' " ;
          rs=db.getResult(strSQL) ;
   if(rs.equals(null ))
     {JOptionPane.showMessageDialog(null,"此书不存在!");
              }
   else
   {
    try {
	 //将游标移动到首位置
      rs.first();
      //在文本框中显示数据集中的数据
      jTextFieldpress.setText(rs.getString("press") );
      jTextFieldauthor.setText(rs.getString("author"));
      jTextFieldaddress.setText(rs.getString("address"));
      jTextFieldpressdate.setText(rs.getString("pressdate"));
      jTextFieldprice.setText(rs.getString("price"));
      jTextFieldcomment.setText(rs.getString("comment"));
    }
    catch (SQLException ex) {
    }

   }
  }
//更新操作
  void jButtonupdate_mouseClicked(MouseEvent e) {
    String strSQL ;
	//生成更新sql语句
    strSQL="update Books set press='"+jTextFieldpress.getText().trim()+"',";
    strSQL= strSQL+" author='"+jTextFieldauthor.getText().trim()+"',";
    strSQL= strSQL+" address='"+jTextFieldaddress.getText().trim()+"',";
    strSQL= strSQL+" pressdate='"+jTextFieldpressdate.getText().trim()+"',";
    strSQL= strSQL+" price='"+jTextFieldprice.getText().trim()+"',";
    strSQL= strSQL+" comment='"+jTextFieldcomment.getText().trim()+"'";
    strSQL= strSQL+  " where bookname='"+jTextFieldname.getText().trim() +"'";
	 //由数据库操作对象执行数据库操作,并返回操作成功失败的提示信息
    if(db.executeSql(strSQL))
              {JOptionPane.showMessageDialog(null,"成功更新!"); }
           else
              { JOptionPane.showMessageDialog(null," 更新失败,请重新操作!");      }

  }
}

class borrowHistoryall_jButtonexit_mouseAdapter extends java.awt.event.MouseAdapter {
  bookUpdate adaptee;

  borrowHistoryall_jButtonexit_mouseAdapter(bookUpdate adaptee) {
    this.adaptee = adaptee;
  }
  public void mouseClicked(MouseEvent e) {
    adaptee.jButtonexit_mouseClicked(e);
  }
}

class bookUpdate_jButtonClear_mouseAdapter extends java.awt.event.MouseAdapter {
  bookUpdate adaptee;

  bookUpdate_jButtonClear_mouseAdapter(bookUpdate adaptee) {
    this.adaptee = adaptee;
  }
  public void mouseClicked(MouseEvent e) {
    adaptee.jButtonClear_mouseClicked(e);
  }
}

class bookUpdate_jButtondicision_mouseAdapter extends java.awt.event.MouseAdapter {
  bookUpdate adaptee;

  bookUpdate_jButtondicision_mouseAdapter(bookUpdate adaptee) {
    this.adaptee = adaptee;
  }
  public void mouseClicked(MouseEvent e) {
    adaptee.jButtondicision_mouseClicked(e);
  }
}

class bookUpdate_jButtonupdate_mouseAdapter extends java.awt.event.MouseAdapter {
  bookUpdate adaptee;

  bookUpdate_jButtonupdate_mouseAdapter(bookUpdate adaptee) {
    this.adaptee = adaptee;
  }
  public void mouseClicked(MouseEvent e) {
    adaptee.jButtonupdate_mouseClicked(e);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -