| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 708 人关注过本帖
标题:如何访问其他包的对象
只看楼主 加入收藏
wangchen223
Rank: 1
等 级:新手上路
帖 子:149
专家分:0
注 册:2006-7-1
收藏
 问题点数:0 回复次数:9 
如何访问其他包的对象
如何访问其他包的对象
我建了2个包,一个是操作数据库的,一个是界面。我想查数据库的数据如果上机则添加到另一个包里的下拉框了,否则不添加。
如何实现?
搜索更多相关主题的帖子: 对象 访问 
2006-07-24 09:33
aiyuheng
Rank: 1
等 级:新手上路
威 望:1
帖 子:656
专家分:0
注 册:2006-1-12
收藏
得分:0 
public 类的对象 在哪都能用

when i want to ask anyone,i will ask myself first.
2006-07-24 10:20
wangchen223
Rank: 1
等 级:新手上路
帖 子:149
专家分:0
注 册:2006-7-1
收藏
得分:0 

不行呀?有没有例题.我跨包了


2006-07-24 10:32
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
把那个包放到你的当前目录下
然后import就可以了

可惜不是你,陪我到最后
2006-07-24 12:03
wangchen223
Rank: 1
等 级:新手上路
帖 子:149
专家分:0
注 册:2006-7-1
收藏
得分:0 

这个我会
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);
}
}


2006-07-24 12:08
wangchen223
Rank: 1
等 级:新手上路
帖 子:149
专家分:0
注 册:2006-7-1
收藏
得分:0 
跨包了,访问另一个包的对象的代码不会写

2006-07-24 12:10
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
import 不就可以了吗?
有那么复杂?

可惜不是你,陪我到最后
2006-07-24 19:37
NiceGirl
Rank: 2
等 级:新手上路
威 望:4
帖 子:909
专家分:0
注 册:2006-6-18
收藏
得分:0 
是啊,import 不就好了

曾经以为百般艰难,蓦然回首,才发现已飞渡千山。。!
2006-07-24 19:41
什么也不会
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-7-24
收藏
得分:0 
就是就是·
2006-07-25 00:02
wangchen223
Rank: 1
等 级:新手上路
帖 子:149
专家分:0
注 册:2006-7-1
收藏
得分:0 
用import不行呀,我在其他的地方建了一个对象,然后在其他地方掉用他的方法不会写。

2006-07-26 10:20
快速回复:如何访问其他包的对象
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034799 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved