📄 chakanliuyan.java
字号:
package bookmanager;import javax.swing.*;import com.borland.jbcl.layout.*;import java.awt.*;import java.sql.*; //引入包java.sql.*;import javax.swing.table.*; //引入包sqljavax.swing.table.*;import java.util.*; //引入包sqljava.util*;import java.awt.event.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class chakanliuyan extends JFrame { //定义结果集 ResultSet rs; //定义数据库操作对象 private DBManager db = new DBManager(); XYLayout xYLayout1 = new XYLayout(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JTextField jTextFielddepartment = new JTextField(); JLabel jLabel4 = new JLabel(); JLabel jLabel5 = new JLabel(); JTextField jTextFieldlydate = new JTextField(); JTextArea jTextArealynr = new JTextArea(); JLabel jLabel6 = new JLabel(); JComboBox jComboBoxprofessional = new JComboBox(); JButton jButtonok = new JButton(); JButton jButtondelete = new JButton(); public chakanliuyan() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { chakanliuyan chakanliuyan = new chakanliuyan(); } private void jbInit() throws Exception { jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setText("所在专业"); xYLayout1.setWidth(588); xYLayout1.setHeight(497); this.getContentPane().setLayout(xYLayout1); jLabel2.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setText("所属院系"); jTextFielddepartment.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFielddepartment.setText(""); jLabel4.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel4.setText("留言内容"); jLabel5.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel5.setText("留言时间"); jTextFieldlydate.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldlydate.setText(""); jTextArealynr.setFont(new java.awt.Font("Dialog", 0, 16)); jTextArealynr.setText(""); jLabel6.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel6.setText("选择用户名点击查询留言按钮显示详细信息"); jButtonok.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonok.setText("查询留言"); jButtondelete.setFont(new java.awt.Font("Dialog", 0, 16)); jButtondelete.setText("删除留言"); this.getContentPane().add(jLabel5, new XYConstraints(313, 112, 73, 36)); this.getContentPane().add(jLabel1, new XYConstraints(52, 66, 80, 31)); this.getContentPane().add(jLabel6, new XYConstraints(55, 16, 434, 29)); this.getContentPane().add(jComboBoxprofessional, new XYConstraints(147, 67, 150, 29)); this.getContentPane().add(jButtonok, new XYConstraints(83, 441, 106, 38)); this.getContentPane().add(jTextFieldlydate, new XYConstraints(394, 115, 143, 30)); this.getContentPane().add(jButtondelete, new XYConstraints(188, 441, 104, 38)); this.getContentPane().add(jLabel2, new XYConstraints(310, 67, 77, 27)); this.getContentPane().add(jTextFielddepartment, new XYConstraints(390, 66, 146, 30)); this.getContentPane().add(jLabel4, new XYConstraints(49, 125, 82, 31)); this.getContentPane().add(jTextArealynr, new XYConstraints(56, 170, 485, 254)); jButtonok.addMouseListener(new chakanliuyan_jButtonok_mouseAdapter(this)); jButtondelete.addMouseListener(new chakanliuyan_jButtondelete_mouseAdapter(this)); } void jButtonok_mouseClicked(MouseEvent e) { String strSQL; //校验书名是否为空 if ( jComboBoxprofessional.getSelectedItem().toString().equals("")) { JOptionPane.showMessageDialog(null, "不许为空!"); return; } //生成sql操作语句,查询要更新的书是否存在,若存在将此书相关信息绑顶到窗体上,若不存在提示并返回 boolean isFirst = true; strSQL = "select ly.* from ly"; if (!jComboBoxprofessional.getSelectedItem().toString().equals("")) { strSQL = strSQL + " where ly.professional='" + jComboBoxprofessional.getSelectedItem().toString() + "'"; isFirst = false; } rs = db.getResult(strSQL); boolean isexist = false; try { isexist = rs.first(); } catch (SQLException ex1) { } //若此书不存在,提示警告信息 if (!isexist) { JOptionPane.showMessageDialog(null, "不存在!"); } else { try { //将游标移动到首位置 rs.first(); //在文本框中显示数据集中的数据 jTextFielddepartment.setText(rs.getString("department")); jTextFieldlydate.setText(rs.getString("lydate")); jTextArealynr.setText(rs.getString("lynr"));} catch (SQLException ex) { } } } void jButtondelete_mouseClicked(MouseEvent e) {String strSQL;strSQL = "delete from ly where ly.professional='" + jComboBoxprofessional.getSelectedItem().toString() + "'";//由数据库操作对象执行数据库操作,并返回操作成功失败的提示信息if (db.executeSql(strSQL)) { JOptionPane.showMessageDialog(null, "成功删除!");}else { JOptionPane.showMessageDialog(null, " 删除失败,请重新操作!");}}class chakanliuyan_jButtonok_mouseAdapter extends java.awt.event.MouseAdapter { chakanliuyan adaptee;chakanliuyan_jButtonok_mouseAdapter(chakanliuyan adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonok_mouseClicked(e); }}class chakanliuyan_jButtondelete_mouseAdapter extends java.awt.event.MouseAdapter { chakanliuyan adaptee; chakanliuyan_jButtondelete_mouseAdapter(chakanliuyan adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtondelete_mouseClicked(e); }} }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -