比如你的Frame对象为f其中有一个JTextField output= new JTextField;
另一个文件为DBClass db.
你可以有两种选择办法
1>在Frame中生成DBClass对象
如在Frame的某个方法中调用
DBClass db=new DBClass(this);
或者
DBClass db=new DBlass();
之后在DBClass中就可以利用传递过来的对象访问output了。
db.setHandle(this);
当然这个setHandle你要自己定义。
2>在DBClass生成Frame
在DBClass的某个方法中调用
Frame f=new yourFrame()
之后调用f.output付值

解决方案 »

  1.   

    我在有main函数的find.java里连接数据库并查询,想把查询结果在
    另一个
    public class view extends JFrame {}
    的.java文件里的
    JTextField output= new JTextField;里输出
    应该怎么办???????????
      

  2.   

    在find.java中建立view对象,例如:
    view v=new view()
    之后调用v.output啊。
      

  3.   

    记住一点如果一个类要访问另外一个类的方法或者属性,必须拥有另一个类的句柄,通常得到句柄有两种方式,一个是在第一个类中创建第二个类,另外就是在第二个类中创建第一个类,之后将自己也就是this传递到第一个类,其实还有一种方式,就是在第三个类中创建第一个和第二个类,之后调用第一个或第二个类中的相应方法传递句柄。
      

  4.   

    我在find.java中
    view frame = new view();
    然后
    frame.output.setText("111");可是在运行的时候根本就没有显示111,
    output中还是什么都没有
      

  5.   

    我坦白,我对窗口界面编程了解的不多,也很少写,你
    在frame.output.setText("111");之后
    调用frame.repaint();是市。
      

  6.   

    调用frame.repaint();了
    可还是没用
      

  7.   

    这样你在view中添加
    public static void main(String args[])
    {
       view v=new view();
       v.output.setText("asdfasdfasdf");
    }
    之后编译运行看有没有。
      

  8.   

    如果这样也不行是你的view有问题,把view的代码帖出来。
      

  9.   

    应该没问题的呀,一大部分都是JB6自己生成的我只加了几个JPanel,设计了一下版面
    public class view extends JFrame {
      JPanel contentPane,top,mid,bottom;
      JTextField input,output;
      JLabel labelup,labelmid,labeldown;
      JButton button;
      BorderLayout borderLayout1 = new BorderLayout();  //Construct the frame
      public view() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //窗口初始化
      public void jbInit() throws Exception  {
        //setIconImage(Toolkit.getDefaultToolkit().createImage(view.class.getResource("[Your Icon]")));
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(borderLayout1);    top = new JPanel(new FlowLayout());
        contentPane.add(top,BorderLayout.NORTH );
        labelup = new JLabel("软件技术基础考试成绩查询");
        top.add(labelup);    mid = new JPanel(new BorderLayout());
        contentPane.add(mid,BorderLayout.SOUTH );    labelmid = new JLabel("请输入准考证号");
        mid.add(labelmid,BorderLayout.WEST );    input = new JTextField(9);
        mid.add(input,BorderLayout.CENTER );    button = new JButton("查询");
        mid.add(button,BorderLayout.EAST );
        bottom = new JPanel();
        mid.add(bottom,BorderLayout.SOUTH );    labeldown = new JLabel("成绩");
        bottom.add(labeldown,BorderLayout.WEST  );    
        bottom.add(output,BorderLayout.EAST  );    this.setSize(new Dimension(400, 120));
        this.setTitle("软件技术基础考试成绩查询系统");
      }//Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }
    }
      

  10.   

    贴错了点儿,应该是这样public class view extends JFrame {
      JPanel contentPane,top,mid,bottom;
      JTextField input,output;
      JLabel labelup,labelmid,labeldown;
      JButton button;
      BorderLayout borderLayout1 = new BorderLayout();  //Construct the frame
      public view() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //窗口初始化
      public void jbInit() throws Exception  {
     
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(borderLayout1);    top = new JPanel(new FlowLayout());
        contentPane.add(top,BorderLayout.NORTH );
        labelup = new JLabel("软件技术基础考试成绩查询");
        top.add(labelup);    mid = new JPanel(new BorderLayout());
        contentPane.add(mid,BorderLayout.SOUTH );    labelmid = new JLabel("请输入准考证号");
        mid.add(labelmid,BorderLayout.WEST );    input = new JTextField(9);
        mid.add(input,BorderLayout.CENTER );    button = new JButton("查询");
        mid.add(button,BorderLayout.EAST );
        bottom = new JPanel();
        mid.add(bottom,BorderLayout.SOUTH );    labeldown = new JLabel("成绩");
        bottom.add(labeldown,BorderLayout.WEST  );    
        bottom.add(output,BorderLayout.EAST  );    this.setSize(new Dimension(400, 120));
        this.setTitle("软件技术基础考试成绩查询系统");
      }//Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }
    }
      

  11.   

    你的input有input = new JTextField(9);
    output怎么没有
      

  12.   

    在bottom.add(output,BorderLayout.EAST  );前面加上
    output = new JTextField(9);
      

  13.   

    有的,粘的时候没粘上
    output = new JTextField(30);
    整个窗体都没问题
    我在view()里定义output.setText("111");就能显示
    只是在find中定义
    view frame = new view();
    frame.output.setText("111");
    没法显示
      

  14.   

    你在view中添加一个函数如下:
    public settext()
    {
      output.setText("asdf");
    }
    之后在
    find中调用
    view frame = new view();
    frame.settext();是是
      

  15.   

    只能是
    public void settext()
    {
      output.setText("asdf");
    }
    才不报错,不加void,就显示有错误.加了void之后能运行了,但还是显示不出来
      

  16.   

    我目前没有环境,不能进行实验,感觉应该可以啊,调用repaint()也不行我就不知道了,看看其他人怎么说。
      

  17.   

    谢谢你的帮忙!!!!!!!!!!!!!!111
    3333333333333333333QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
      

  18.   

    在frame.settext();
    后面调用frame.validate()是是,我对窗口编程不是很了解,惭愧。
      

  19.   

    我用你的代码试了一下,可以显示。
    view类和你的一样,在另一个类中调用:
             view v = new view();
            v.output.setText("haha");
            v.setVisible(true);是不是你没有用 v.setVisible(true);
      

  20.   

    //comfort,我看了挺有趣了,自己也run了一下
    在view写了main,然后new 了2个view来让第二个
    设置对方,都是可以的哦
    package test;import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;public class view extends JFrame {
      JPanel contentPane,top,mid,bottom;
      view other;
      JTextField input,output;
      JLabel labelup,labelmid,labeldown;
      JButton button=new JButton("");
      BorderLayout borderLayout1 = new BorderLayout();
      private JButton jButton1 = new JButton();  //Construct the frame
      public view(view other1) {
        other = other1;
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      public view() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //窗口初始化
      public void jbInit() throws Exception  {
        output = new JTextField(30);
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(borderLayout1);    top = new JPanel(new FlowLayout());
        jButton1.setText(" 点我吧,可以设置另一个窗口");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton1_actionPerformed(e);
          }
        });
        contentPane.add(top,BorderLayout.NORTH );
        labelup = new JLabel("软件技术基础考试成绩查询");
        top.add(jButton1, null);
        top.add(labelup);    mid = new JPanel(new BorderLayout());
        contentPane.add(mid,BorderLayout.SOUTH );    labelmid = new JLabel("请输入准考证号");
        mid.add(labelmid,BorderLayout.WEST );    input = new JTextField(9);
        mid.add(input,BorderLayout.CENTER );    button = new JButton("查询");
        mid.add(button,BorderLayout.EAST );
        bottom = new JPanel();
        mid.add(bottom,BorderLayout.SOUTH );    labeldown = new JLabel("成绩");
        bottom.add(labeldown,BorderLayout.WEST  );
        bottom.add(output,BorderLayout.EAST  );    this.setSize(new Dimension(400, 120));
        this.setTitle("软件技术基础考试成绩查询系统");
      }//Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }  public void setother(view mother)
      {
        mother.output.setText("别人设置我了哦");
        System.out.println("click");
      }  public static void main(String[] args) {
       view v=new view();
       v.output.setText("我是窗口1,不要点我啊");
       v.pack();
       v.setVisible(true);
       view v1=new view(v);
       v1.output.setText("我是窗口2,请先把我移到一边,再点我啊!");
       v1.pack();
       v1.setVisible(true);
      }  void jButton1_actionPerformed(ActionEvent e) {
        this.setother(other);
      }
    }