Java 如何通过另一个JFrame修改一个JFrame?

Java 如何通过另一个JFrame修改一个JFrame?,java,swing,button,jframe,textarea,Java,Swing,Button,Jframe,Textarea,我有两个JA框架,B.B有一个文本区域。我想在B中的文本区域添加一些文本 单击a中的按钮。以下是我的代码: JButton btn = new JButton("Text"); btnButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { b.textArea.setText("Button clicked"); } }); btn

我有两个JA框架,B.B有一个文本区域。我想在B中的文本区域添加一些文本 单击a中的按钮。以下是我的代码:

JButton btn = new JButton("Text");
btnButton_1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        b.textArea.setText("Button clicked");
    }
});
btnButton_1.setBounds(10, 45, 89, 23);
frmA.getContentPane().add(btnButton_1);
b是b类的对象 textArea是类B中的JTextArea变量名
使用组件的重绘方法

JButton btn = new JButton("Text");
        btnButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                b.textArea.setText("Button clicked");
                b.frameB.repaint();
            }
        });
        btnButton_1.setBounds(10, 45, 89, 23);
        frmA.getContentPane().add(btnButton_1);

在向JTextArea添加文本后,尝试在b中调用Repain。不要重新绘制任何内容,为了更好地帮助您尽快发布一个短、可运行、可编译的SSCCE/MCVE。您可以使用b.textArea.appendyour text;你的文本区是公共的吗?你能解释一下你的答案吗?什么是重绘方法。当我按下按钮时没有显示@用户3417593-请查看我的最新帖子。你应该重新粉刷框架本身。我重新粉刷了框架,但同样的东西不起作用。我还尝试重新绘制文本区域。又一次没用了。你试过这个吗?@user3417593-你能发布这两个java代码吗?但不是全部,只是要点。