小问题,请教各位了:
Class myDialog  //这是一个窗体程序,其中有一个jText的文本框
{
   T t=new T; //这是一个自定义类
   ....
}Class T
{
   //现在我想在内中对,myDialog类中的jText进行修改,该怎么操作,谢谢!
}

解决方案 »

  1.   

    在T中添加一个method,
    public modifyJText(JText t){
    }
    这样,当有一个T的实例后,就可以把myDialog中的JText作为参数进行修改了。
      

  2.   

    就是按照 java_augur(听着音乐)所说的做
      

  3.   

    在T中设计修改Jtext的设计方法就行,这也符合面向对象的设计思想。
      

  4.   

    不是这个意思,我要在class T中 随时修改myDialog中jText的内容!这该如何操作?
      

  5.   

    可以说详细点吗?如何在T中加事件通知myDialog?
    谢谢了
      

  6.   

    在T中添加了方法,就可以在myDialog中调用这方法随时改变JText.
    具体实现参照下面的程序。注意去掉序号!
      

  7.   

    1. import java.awt.*;
     2. import java.awt.event.*;
     3. import java.util.*;
     4. import javax.swing.*;
     5. import javax.swing.Timer;
     6.
     7. public class InnerClassTest
     8. {
     9.    public static void main(String[] args)
    10.    {
    11.       TalkingClock clock = new TalkingClock(1000, true);
    12.       clock.start();
    13.
    14.       // keep program running until user selects "Ok"
    15.       JOptionPane.showMessageDialog(null, "Quit program?");
    16.       System.exit(0);
    17.    }
    18. }
    19.
    20. /**
    21.    A clock that prints the time in regular intervals.
    22. */
    23. class TalkingClock
    24. {
    25.    /**
    26.       Constructs a talking clock
    27.       @param interval the interval between messages (in milliseconds)
    28.       @param beep true if the clock should beep
    29.    */
    30.    public TalkingClock(int interval, boolean beep)
    31.    {
    32.       this.interval = interval;
    33.       this.beep = beep;
    34.    }
    35.
    36.    /**
    37.       Starts the clock.
    38.    */
    39.    public void start()
    40.    {
    41.       ActionListener listener = new TimePrinter();
    42.       Timer t = new Timer(interval, listener);
    43.       t.start();
    44.    }
    45.
    46.    private int interval;
    47.    private boolean beep;
    48.
    49.    private class TimePrinter implements ActionListener
    50.    {
    51.       public void actionPerformed(ActionEvent event)
    52.       {
    53.          Date now = new Date();
    54.          System.out.println("At the tone, the time is " + now);
    55.          if (beep) Toolkit.getDefaultToolkit().beep();
    56.       }
    57.    }
    58. }