我建了2个包,一个是操作数据库的,一个是界面。我想查数据库的数据如果上机则添加到另一个包里的下拉框了,否则不添加。
如何实现?
这个我会
package after.dao;
import after.dbManager.Link;
import client.ShangjiFrame;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Connection;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Daocomputer {
private Connection con;
private static int temp2=0,i=0;
public Daocomputer() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void querycomputer(String onUse)//察看机器使用
{
Link temp=new Link();
con=temp.getConnection();
try
{
ResultSet rs=null;
PreparedStatement pstmt=con.prepareStatement("select *from computer where onUse=0");
rs=pstmt.executeQuery();
if(temp2==0)
while (rs.next())
{
temp2++;
}
for(;i<temp2;i++)
{
rs.absolute(i);
}
//这里添加下拉框内容!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
catch (SQLException e)
{
}
}
public static void main(String[]args)
{
}
private void jbInit() throws Exception {
}
}
package client;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.JComboBox;
import javax.swing.JTextPane;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ShangjiFrame extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JTextPane txtkahao = new JTextPane();
JTextPane txtpass = new JTextPane();
JTextPane txttime = new JTextPane();
JButton cmdok = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel5 = new JLabel();
JTextPane txtname = new JTextPane();
public ShangjiFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
public void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
jLabel1.setText("机器号");
jLabel1.setBounds(new Rectangle(22, 29, 53, 15));
jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
jLabel2.setText("卡号");
jLabel2.setBounds(new Rectangle(25, 82, 34, 16));
jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
jLabel3.setText("密码");
jLabel3.setBounds(new Rectangle(25, 110, 34, 16));
jLabel4.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
jLabel4.setText("上机时间");
jLabel4.setBounds(new Rectangle(23, 138, 90, 27));
contentPane.setToolTipText("");
jComboBox1.setBounds(new Rectangle(76, 28, 111, 18));
txtkahao.setText("");
txtkahao.setBounds(new Rectangle(78, 83, 105, 14));
txtpass.setText("");
txtpass.setBounds(new Rectangle(79, 108, 103, 18));
txttime.setText("");
txttime.setBounds(new Rectangle(90, 139, 97, 18));
cmdok.setBounds(new Rectangle(39, 202, 73, 25));
cmdok.setText("确定");
cmdok.addActionListener(new ShangjiFrame_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(153, 200, 73, 25));
jButton2.setText("取消");
jButton2.addActionListener(new ShangjiFrame_jButton2_actionAdapter(this));
jLabel5.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
jLabel5.setText("用户名");
jLabel5.setBounds(new Rectangle(17, 55, 50, 20));
txtname.setBounds(new Rectangle(77, 56, 109, 16));
contentPane.add(jLabel1);
contentPane.add(jComboBox1);
contentPane.add(cmdok);
contentPane.add(jButton2);
contentPane.add(jLabel2);
contentPane.add(txttime);
contentPane.add(jLabel4);
contentPane.add(jLabel3);
contentPane.add(txtpass);
contentPane.add(txtkahao);
contentPane.add(jLabel5);
contentPane.add(txtname);
}
public void jButton1_actionPerformed(ActionEvent e) {
}
public void jButton2_actionPerformed(ActionEvent e) {
}
}
class ShangjiFrame_jButton2_actionAdapter implements ActionListener {
private ShangjiFrame adaptee;
ShangjiFrame_jButton2_actionAdapter(ShangjiFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class ShangjiFrame_jButton1_actionAdapter implements ActionListener {
private ShangjiFrame adaptee;
ShangjiFrame_jButton1_actionAdapter(ShangjiFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}