📄 singledataclassframe.java~76~
字号:
package dbSwing;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.dx.sql.dataset.*;import com.borland.dbswing.*;public class SingleDataClassFrame extends JFrame implements ActionListener { JPanel contentPane; Database database1 = new Database(); QueryDataSet queryDataSet1 = new QueryDataSet(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JLabel jLabel4 = new JLabel(); JLabel jLabel5 = new JLabel(); JLabel jLabel6 = new JLabel(); //创建数据显示类 JdbTextField jdbTextField1 = new JdbTextField(); JdbTextField jdbTextField2 = new JdbTextField(); JdbTextField jdbTextField3 = new JdbTextField(); JdbTextField jdbTextField4 = new JdbTextField(); JdbLabel jdbLabel1 = new JdbLabel(); JdbTextPane jdbTextPane1 = new JdbTextPane(); JdbCheckBox jdbCheckBox1 = new JdbCheckBox(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JButton jButton3 = new JButton(); JButton jButton4 = new JButton(); public SingleDataClassFrame() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(null); this.setSize(new Dimension(415, 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")); //取得books数据表的记录 queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor( database1, "select * from books", null, true, Load.ALL)); jLabel1.setText("图书的索引号:"); jLabel1.setBounds(new Rectangle(17, 18, 92, 16)); jLabel2.setBounds(new Rectangle(258, 18, 76, 16)); jLabel2.setText("类别索引:"); jLabel3.setBounds(new Rectangle(17, 51, 79, 16)); jLabel3.setToolTipText(""); jLabel3.setText("图书名字:"); jLabel4.setBounds(new Rectangle(17, 83, 61, 16)); jLabel4.setText("作者:"); jLabel5.setBounds(new Rectangle(213, 83, 68, 16)); jLabel5.setText("出版商:"); jLabel6.setBounds(new Rectangle(17, 116, 73, 16)); jLabel6.setToolTipText(""); jLabel6.setText("图书摘要:"); jdbTextField1.setBounds(new Rectangle(100, 18, 150, 22)); jdbLabel1.setBounds(new Rectangle(340, 18, 46, 16)); jdbLabel1.setBorder(BorderFactory.createEtchedBorder()); jdbTextField2.setCaretPosition(0); jdbTextField2.setBounds(new Rectangle(100, 51, 219, 22)); jdbTextField3.setBounds(new Rectangle(100, 83, 108, 22)); jdbTextField4.setBounds(new Rectangle(278, 83, 108, 22)); jdbTextPane1.setBorder(BorderFactory.createEtchedBorder()); jdbTextPane1.setBounds(new Rectangle(17, 137, 370, 59)); jdbCheckBox1.setText("在库"); jdbCheckBox1.setBounds(new Rectangle(342, 51, 59, 25)); //设置数据类的数据源和字段 jdbTextField1.setDataSet(queryDataSet1); jdbTextField1.setColumnName("serialId"); jdbLabel1.setDataSet(queryDataSet1); jdbLabel1.setColumnName("categoryId"); jdbTextField2.setDataSet(queryDataSet1); jdbTextField2.setColumnName("bookName"); jdbTextField3.setDataSet(queryDataSet1); jdbTextField3.setColumnName("author"); jdbTextField4.setDataSet(queryDataSet1); jdbTextField4.setColumnName("publisher"); jdbTextPane1.setDataSet(queryDataSet1); jdbTextPane1.setColumnName("content"); jdbCheckBox1.setDataSet(queryDataSet1); jdbCheckBox1.setColumnName("isBorrow"); //设置按钮的属性 jButton1.setBounds(new Rectangle(17, 216, 73, 25)); jButton2.setBounds(new Rectangle(112, 216, 73, 25)); jButton3.setBounds(new Rectangle(207, 216, 73, 25)); jButton4.setBounds(new Rectangle(302, 216, 85, 25)); jButton1.setText("第一条"); jButton2.setText("上一条"); jButton3.setText("下一条"); jButton4.setText("最后一条"); jButton1.setActionCommand("first"); jButton2.setActionCommand("prior"); jButton3.setActionCommand("next"); jButton4.setActionCommand("last"); jButton1.addActionListener(this); jButton2.addActionListener(this); jButton3.addActionListener(this); jButton4.addActionListener(this); //为窗口加入各个控件 contentPane.add(jLabel1, null); contentPane.add(jLabel2, null); contentPane.add(jLabel3, null); contentPane.add(jLabel4, null); contentPane.add(jLabel5, null); contentPane.add(jLabel6, null); contentPane.add(jdbLabel1, null); contentPane.add(jdbTextField1, null); contentPane.add(jdbTextField2, null); contentPane.add(jdbTextField3, null); contentPane.add(jdbTextField4, null); contentPane.add(jdbCheckBox1, null); contentPane.add(jdbTextPane1, null); contentPane.add(jButton1, null); contentPane.add(jButton2, null); contentPane.add(jButton3, null); contentPane.add(jButton4, null); } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } public void actionPerformed(ActionEvent e) { String actionComm = e.getActionCommand(); if (actionComm.equals("first")) { //显示第1条记录 queryDataSet1.first(); } if (actionComm.equals("prior")) { //显示上1条记录 queryDataSet1.prior(); } if (actionComm.equals("next")) { //显示下1条记录 queryDataSet1.next(); } if (actionComm.equals("last")) { //显示最后1条记录 queryDataSet1.last(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -