📄 multidatapleclassframe1.java
字号:
package dbswing;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.dx.sql.dataset.*;
import com.borland.dx.dataset.*;
import com.borland.dbswing.*;
public class MultiDatapleClassFrame1 extends JFrame implements ActionListener {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
Database database1 = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
QueryDataSet queryDataSet2 = new QueryDataSet();
Column column1 = new Column();
TableScrollPane tableScrollPane1 = new TableScrollPane();
JdbTable jdbTable1 = new JdbTable();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JdbComboBox jdbComboBox1 = new JdbComboBox();
TableScrollPane tableScrollPane2 = new TableScrollPane();
JdbList jdbList1 = new JdbList();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
public MultiDatapleClassFrame1() {
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));
//取得books数据表的记录
queryDataSet2.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(
database1, "select * from books", null, true, Load.ALL));
//设置字段属性
column1.setColumnName("categoryId");
column1.setDataType(com.borland.dx.dataset.Variant.INT);
column1.setPickList(new com.borland.dx.dataset.PickListDescriptor(
queryDataSet1, new String[] {"ID"}
, new String[] {"CATEGORYNAME"}
, new String[] {"CATEGORYID"}
, "CATEGORYNAME", false));
column1.setTableName("books");
column1.setServerColumnName("categoryId");
column1.setSqlType(4);
//为QueryDataSet类加入设置后的字段
queryDataSet2.setColumns(new Column[] {column1});
jdbComboBox1.setPreferredSize(new Dimension(100, 22));
tableScrollPane2.setPreferredSize(new Dimension(100, 70));
//设置数据显示类的数据源和字段
jdbComboBox1.setColumnName("categoryId");
jdbComboBox1.setDataSet(queryDataSet2);
jdbList1.setColumnName("categoryId");
jdbList1.setDataSet(queryDataSet2);
jdbTable1.setDataSet(queryDataSet2);
//设置按钮的属性
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);
jPanel1.add(jdbComboBox1, null);
jPanel1.add(tableScrollPane2, null);
tableScrollPane1.getViewport().add(jdbTable1, null);
tableScrollPane2.getViewport().add(jdbList1, null);
jPanel2.add(jButton1, null);
jPanel2.add(jButton2, null);
jPanel2.add(jButton3, null);
jPanel2.add(jButton4, null);
contentPane.add(tableScrollPane1, BorderLayout.CENTER);
contentPane.add(jPanel1, BorderLayout.NORTH);
contentPane.add(jPanel2, BorderLayout.SOUTH);
}
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条记录
queryDataSet2.first();
}
if (actionComm.equals("prior")) {
//显示上1条记录
queryDataSet2.prior();
}
if (actionComm.equals("next")) {
//显示下1条记录
queryDataSet2.next();
}
if (actionComm.equals("last")) {
//显示最后1条记录
queryDataSet2.last();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -