English 中文(简体)
可以在另一类中设定左翼成分的数值。
原标题:can t set values in swing components in another class

我有这个班子。

public class MyFrame extends JFrame{
   JTextArea textArea;
  public MyFrame(){
   setSize(100,100);
   textArea = new JTextArea(50,50);
   Container content = getContentPane(); 
   content.add(textArea);
  }
 public static void main(String[] args){
          JFrame frame = new MyFrame();  
          frame.show();
          UpdateText u = new UpdateText();
          u.settext("Helloworld");
      }
}

我有另一个类别,将确定<代码>textArea的案文,其中我把我的Frame延伸到另一个类别中的文本Area。

public class UpdateText extends MyFrame{
    public void settext(String msg){
     textArea.setText(msg);
    }
}

然后,我即时发送最新情况,并称其职能为文字,但案文似乎在《全球倡议》中出现。

最佳回答

首先,除非你想要采取不同的行为,否则不会凌驾于<条码>>>>>tText()。 第二,你不需要扩大。 你们必须做的是遵循这些简单步骤,你们会ll!

  1. 在<代码>UpdateText类别中,将以下几条线划入:

    MyFrame gui;
    
    public UpdateText(MyFrame in) {
        gui = in;
    }
    
  2. 在MyFrame“阶级”中,将这条线放在一开始:

    UpdateText ut = new UpdateText(this);
    

现在,你可以提及<代码>中的所有内容。 缩略语 例如,你想改变你的文本。 守则如下:

gui.textArea.setText("Works!");

欢乐!

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签