📄 notepad_dialog.java
字号:
package psa;import java.awt.*;import javax.swing.*;import com.borland.jbcl.layout.*;import com.borland.dbswing.*;import com.borland.dx.sql.dataset.*;import com.borland.dx.dataset.*;import java.awt.event.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class NotePad_Dialog extends JDialog { JPanel panel1 = new JPanel(); JPanel jPanel1 = new JPanel(); JLabel jLabel1 = new JLabel(); XYLayout xYLayout2 = new XYLayout(); JComboBox jComboBox1 = new JComboBox(); JLabel jLabel2 = new JLabel(); JTextField jTextField1 = new JTextField(); JButton jButton1 = new JButton(); TableScrollPane tableScrollPane1 = new TableScrollPane(); JdbTable jdbTable1 = new JdbTable(); JPanel jPanel2 = new JPanel(); JLabel jLabel3 = new JLabel(); XYLayout xYLayout3 = new XYLayout(); JdbTextField jdbTextField1 = new JdbTextField(); JdbTextField jdbTextField2 = new JdbTextField(); JLabel jLabel4 = new JLabel(); JdbTextField jdbTextField3 = new JdbTextField(); JLabel jLabel5 = new JLabel(); JLabel jLabel6 = new JLabel(); JScrollPane jScrollPane1 = new JScrollPane(); JdbTextArea jdbTextArea1 = new JdbTextArea(); JButton jButton2 = new JButton(); JButton jButton3 = new JButton(); JButton jButton4 = new JButton(); JButton jButton5 = new JButton(); Database database1 = new Database(); QueryDataSet queryDataSet1 = new QueryDataSet(); Column column1 = new Column(); Column column2 = new Column(); Column column3 = new Column(); Column column4 = new Column(); Column column5 = new Column(); GridBagLayout gridBagLayout1 = new GridBagLayout(); public NotePad_Dialog(Frame frame, String title, boolean modal) { super(frame, title, modal); try { jbInit(); pack(); } catch(Exception ex) { ex.printStackTrace(); } } public NotePad_Dialog() { this(null, "", false); } private void jbInit() throws Exception { panel1.setLayout(gridBagLayout1); jPanel1.setBorder(BorderFactory.createEtchedBorder()); jPanel1.setLayout(xYLayout2); jLabel1.setFont(new java.awt.Font("DialogInput", 0, 12)); jLabel1.setText("查询条件:"); jLabel2.setText("查询内容:"); jLabel2.setFont(new java.awt.Font("DialogInput", 0, 12)); jTextField1.setText(""); jButton1.setFont(new java.awt.Font("DialogInput", 0, 12)); jButton1.setText("查询"); jButton1.addActionListener(new NotePad_Dialog_jButton1_actionAdapter(this)); jPanel2.setBorder(BorderFactory.createEtchedBorder()); jPanel2.setLayout(xYLayout3); jLabel3.setFont(new java.awt.Font("DialogInput", 0, 12)); jLabel3.setText("日期:"); jLabel4.setText("类别:"); jLabel4.setFont(new java.awt.Font("DialogInput", 0, 12)); jdbTextField1.setText(""); jdbTextField1.setColumnName("date"); jdbTextField1.setDataSet(queryDataSet1); jdbTextField2.setText(""); jdbTextField2.setColumnName("sort"); jdbTextField2.setDataSet(queryDataSet1); jLabel5.setText("标题:"); jLabel5.setFont(new java.awt.Font("DialogInput", 0, 12)); jdbTextField3.setText(""); jdbTextField3.setColumnName("caption"); jdbTextField3.setDataSet(queryDataSet1); jLabel6.setFont(new java.awt.Font("DialogInput", 0, 12)); jLabel6.setText("内容:"); jButton2.setText("新增"); jButton2.addActionListener(new NotePad_Dialog_jButton2_actionAdapter(this)); jButton2.setFont(new java.awt.Font("DialogInput", 0, 12)); jButton3.setText("保存"); jButton3.addActionListener(new NotePad_Dialog_jButton3_actionAdapter(this)); jButton3.setFont(new java.awt.Font("DialogInput", 0, 12)); jButton4.setText("删除"); jButton4.addActionListener(new NotePad_Dialog_jButton4_actionAdapter(this)); jButton4.setFont(new java.awt.Font("DialogInput", 0, 12)); jButton5.setText("退出"); jButton5.addActionListener(new NotePad_Dialog_jButton5_actionAdapter(this)); jButton5.setFont(new java.awt.Font("DialogInput", 0, 12)); database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:psa", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver")); queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from notepad;", null, true, Load.ALL)); column1.setCaption("编号"); column1.setColumnName("ID"); column1.setDataType(com.borland.dx.dataset.Variant.INT); column1.setRowId(true); column1.setTableName("notepad"); column1.setVisible(com.borland.jb.util.TriStateProperty.FALSE); column1.setServerColumnName("ID"); column1.setSqlType(4); column2.setCaption("日期"); column2.setColumnName("date"); column2.setDataType(com.borland.dx.dataset.Variant.STRING); column2.setPrecision(20); column2.setTableName("notepad"); column2.setServerColumnName("date"); column2.setSqlType(12); column3.setCaption("类型"); column3.setColumnName("sort"); column3.setDataType(com.borland.dx.dataset.Variant.STRING); column3.setPrecision(20); column3.setTableName("notepad"); column3.setServerColumnName("sort"); column3.setSqlType(12); column4.setCaption("标题"); column4.setColumnName("caption"); column4.setDataType(com.borland.dx.dataset.Variant.STRING); column4.setPrecision(30); column4.setTableName("notepad"); column4.setServerColumnName("caption"); column4.setSqlType(12); column5.setCaption("内容"); column5.setColumnName("comments"); column5.setDataType(com.borland.dx.dataset.Variant.STRING); column5.setSearchable(false); column5.setTableName("notepad"); column5.setVisible(com.borland.jb.util.TriStateProperty.FALSE); column5.setServerColumnName("comments"); queryDataSet1.setColumns(new Column[] {column1, column2, column3, column4, column5}); jdbTable1.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); jdbTable1.setDataSet(queryDataSet1); jdbTable1.setEditable(false); jdbTextArea1.setColumnName("comments"); jdbTextArea1.setDataSet(queryDataSet1); this.setResizable(false); this.setTitle("日常记事"); getContentPane().add(panel1); panel1.add(jPanel1, new GridBagConstraints(0, 0, 5, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 9, 0, 14), 19, 21)); jPanel1.add(jLabel1, new XYConstraints(13, 26, -1, -1)); jPanel1.add(jComboBox1, new XYConstraints(81, 24, 129, -1)); jPanel1.add(jButton1, new XYConstraints(489, 19, 84, -1)); jPanel1.add(jTextField1, new XYConstraints(302, 24, 162, -1)); jPanel1.add(jLabel2, new XYConstraints(229, 27, -1, -1)); panel1.add(tableScrollPane1, new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(13, 9, 0, 0), -234, -118)); panel1.add(jPanel2, new GridBagConstraints(2, 1, 3, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 8, 0, 14), 9, 9)); jPanel2.add(jLabel3, new XYConstraints(14, 18, -1, -1)); jPanel2.add(jdbTextField1, new XYConstraints(58, 15, 93, -1)); jPanel2.add(jLabel4, new XYConstraints(168, 17, -1, -1)); jPanel2.add(jdbTextField2, new XYConstraints(212, 14, 123, -1)); jPanel2.add(jLabel5, new XYConstraints(14, 53, -1, -1)); jPanel2.add(jdbTextField3, new XYConstraints(58, 50, 278, -1)); jPanel2.add(jLabel6, new XYConstraints(15, 90, -1, -1)); jPanel2.add(jScrollPane1, new XYConstraints(15, 113, 326, 178)); panel1.add(jButton2, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(24, 72, 21, 0), 26, 0)); panel1.add(jButton5, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(26, 49, 21, 69), 26, 0)); panel1.add(jButton4, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(26, 44, 21, 0), 26, 0)); panel1.add(jButton3, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(25, 49, 21, 0), 26, 0)); jScrollPane1.getViewport().add(jdbTextArea1, null); tableScrollPane1.getViewport().add(jdbTable1, null); jComboBox1.addItem("按类别查询"); jComboBox1.addItem("按标题查询"); jComboBox1.setSelectedIndex(-1); } void jButton1_actionPerformed(ActionEvent e) { if(jComboBox1.getSelectedIndex()<0){ JOptionPane.showMessageDialog(this,"请选择查询条件"); return; } if(jTextField1.getText().length()==0){ JOptionPane.showMessageDialog(this,"请输入查询内容"); return; } String condition = "caption"; if(jComboBox1.getSelectedIndex()==0) condition="sort"; if(queryDataSet1.isOpen()) queryDataSet1.close(); String sql = "select * from notepad where "+condition+" = \'" + jTextField1.getText() + "\'"; try{ queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor( database1,sql, null, true,Load.ALL)); queryDataSet1.open(); }catch(Exception ex){ JOptionPane.showMessageDialog(this,ex.toString()); } } void jButton2_actionPerformed(ActionEvent e) { queryDataSet1.insertRow(false); } void jButton3_actionPerformed(ActionEvent e) { try{ queryDataSet1.post(); queryDataSet1.saveChanges(); queryDataSet1.refresh(); }catch(Exception ex){ queryDataSet1.refresh(); JOptionPane.showMessageDialog(this,"注册失败!","提示",JOptionPane.ERROR_MESSAGE); } } void jButton4_actionPerformed(ActionEvent e) { try{ queryDataSet1.deleteRow(); queryDataSet1.post(); queryDataSet1.saveChanges(); queryDataSet1.refresh(); }catch(Exception ex){ queryDataSet1.refresh(); JOptionPane.showMessageDialog(this,"删除失败","提示",JOptionPane.ERROR_MESSAGE); } } void jButton5_actionPerformed(ActionEvent e) { this.dispose(); }}class NotePad_Dialog_jButton1_actionAdapter implements java.awt.event.ActionListener { NotePad_Dialog adaptee; NotePad_Dialog_jButton1_actionAdapter(NotePad_Dialog adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}class NotePad_Dialog_jButton2_actionAdapter implements java.awt.event.ActionListener { NotePad_Dialog adaptee; NotePad_Dialog_jButton2_actionAdapter(NotePad_Dialog adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}class NotePad_Dialog_jButton3_actionAdapter implements java.awt.event.ActionListener { NotePad_Dialog adaptee; NotePad_Dialog_jButton3_actionAdapter(NotePad_Dialog adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton3_actionPerformed(e); }}class NotePad_Dialog_jButton4_actionAdapter implements java.awt.event.ActionListener { NotePad_Dialog adaptee; NotePad_Dialog_jButton4_actionAdapter(NotePad_Dialog adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton4_actionPerformed(e); }}class NotePad_Dialog_jButton5_actionAdapter implements java.awt.event.ActionListener { NotePad_Dialog adaptee; NotePad_Dialog_jButton5_actionAdapter(NotePad_Dialog adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton5_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -