📄 locateframe.java
字号:
package oftenuse;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.dx.sql.dataset.*;import com.borland.dbswing.*;import com.borland.dx.dataset.*;public class LocateFrame extends JFrame implements ActionListener { JPanel contentPane; BorderLayout borderLayout1 = new BorderLayout(); Database database1 = new Database(); QueryDataSet queryDataSet1 = new QueryDataSet(); TableScrollPane tableScrollPane1 = new TableScrollPane(); JdbTable jdbTable1 = new JdbTable(); JPanel jPanel1 = new JPanel(); JTextField jTextField1 = new JTextField(); JButton jButton1 = new JButton(); JLabel jLabel1 = new JLabel(); public LocateFrame() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(400, 300)); this.setTitle("数据表定位操作示例"); //建立与SQLServer的books数据库的联接 database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor( "jdbc:microsoft:sqlserver://bemyfriend:1433;DatabaseName=books", "sa", "", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver")); //取得bookcategory数据表的记录 queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor( database1, "select * from bookcategory", null, true, Load.ALL)); jLabel1.setText("图书类别名字:"); jTextField1.setPreferredSize(new Dimension(100, 22)); jButton1.setText("定位"); jButton1.addActionListener(this); //设置表格的数据源 jdbTable1.setDataSet(queryDataSet1); jPanel1.add(jLabel1, null); jPanel1.add(jTextField1, null); jPanel1.add(jButton1, null); tableScrollPane1.getViewport().add(jdbTable1, null); contentPane.add(tableScrollPane1, BorderLayout.CENTER); contentPane.add(jPanel1, BorderLayout.NORTH); } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } public void actionPerformed(ActionEvent e) { String searchVal = jTextField1.getText(); //根据数据类和字段名创建记录类 DataRow searchRow = new DataRow(queryDataSet1, "categoryName"); searchRow.setString("categoryName", searchVal); //Locate.PARTIAL表示只要字符串部分相同便可,Locate.FIRST表示搜索第1条相同记录 queryDataSet1.locate(searchRow, Locate.PARTIAL + Locate.FIRST); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -