我制作了许多对象,例如 JButton、JLabel、JCheckBox 等。我已经为对象添加了一个事件侦听器。像这样。对象 obj = new obj(); obj.listneraddActionListener(){}; 但是,如果侦听器使用其他对象,则必须在侦听器代码之前创建该对象。我在考虑是提前排序对象定义还是把所有监听拉到下面。我该怎么办?
编辑:对不起,我没有发布,因为代码太大了。以下是代码的一部分。我从复选框(chkName、chkAddress、chkType、chkComment)中收到错误消息
JButton btnSearch = new JButton("");
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String str = "";
ResultSet rsSid, rsNM = null;
int count = 0;
if (chkName.isSelected()) {str += "(SELECT " + tableName + "_SID FROM " + tableName + " WHERE " + tableName + "_NM LIKE '%" + txtSearch.getText() + "%') UNION "; ++count;}
if (chkAddress.isSelected()) {str += "(SELECT " + tableName + "_SID FROM " + tableName + " WHERE " + "ADDR LIKE '%" + txtSearch.getText() +"%') UNION "; ++count;}
if (chkType.isSelected()) {str += "(SELECT " + tableName + "_SID FROM " + tableName + " WHERE " + "TYPE LIKE '%" + txtSearch.getText() +"%') UNION "; ++count;}
if (chkComment.isSelected()) {str += "(SELECT " + tableName + "_SID FROM " + tableName + " WHERE " + "COMMENT LIKE '%" + txtSearch.getText() +"%') UNION "; ++count;}
if (count == 0) return;
if (txtSearch.getText() != "")
str = str.substring(0, str.length() - 7) + ';';
else
str = "SELECT * FROM " + tableName;
rsSid = jdbc.executeQuery(conn, str);
try {
behindList.clear();
lstSRmodel.clear();
TableSummary temp = new TableSummary();
while(rsSid.next()) {
for (int i = 1; i <= rsSid.getMetaData().getColumnCount(); ++i) {
temp.TABLE_SID = rsSid.getInt(i);
}
}
});
呼啦一阵风
蝴蝶刀刀
梦里花落0921
随时随地看视频慕课网APP
相关分类