编写一个图形界面的Application程序,包括两个文本框和一个按钮。

当单击按钮时,可以把一个文本框中的内容复制到另一个文本框中。要求用Swing组件实现。

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class Test {
public static void main(String args[]) {
JFrame frame = new JFrame();
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
final JTextArea textArea1 = new JTextArea(20, 30);
final JTextArea textArea2 = new JTextArea(20, 30);
JButton button = new JButton("=>");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
textArea2.setText(textArea1.getText());
}
});
frame.add(textArea1);
frame.add(button);
frame.add(textArea2);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网