[英]how to modify a JFrame by another JFrame?
I have two JFrames A, and B. B has a textArea. 我有两个JFrames A和B。B有一个textArea。 I want to add some text to that TextArea in B by clicking a button in A. here is my code: 我想通过单击A中的按钮向B中的TextArea添加一些文本。这是我的代码:
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);
Use repaint() method of components. 使用组件的repaint()方法。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.