展开全部
public class AddText {
JFrame jf ;
JTextField jtf;
JTextArea jta;
JButton jbAdd;
String totalStr = "";
public AddText(){
jf = new JFrame();
jtf = new JTextField();
jta = new JTextArea();
jbAdd = new JButton("添加");
jf.setLayout(null);
jtf.setBounds(10, 10, 100, 30);
jbAdd.setBounds(120, 10, 80, 30);
jta.setBounds(10, 50, 300, 300);
jf.add(jtf);
jf.add(jbAdd);
jf.add(jta);
jf.setSize(400, 400);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//注册监听器
jbAdd.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
String str = jtf.getText();
totalStr = totalStr+str;
jta.setText(totalStr);
jtf.setText("");
}
});
}
public static void main(String[] args) {
new AddText();
}
}
JFrame jf ;
JTextField jtf;
JTextArea jta;
JButton jbAdd;
String totalStr = "";
public AddText(){
jf = new JFrame();
jtf = new JTextField();
jta = new JTextArea();
jbAdd = new JButton("添加");
jf.setLayout(null);
jtf.setBounds(10, 10, 100, 30);
jbAdd.setBounds(120, 10, 80, 30);
jta.setBounds(10, 50, 300, 300);
jf.add(jtf);
jf.add(jbAdd);
jf.add(jta);
jf.setSize(400, 400);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//注册监听器
jbAdd.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
String str = jtf.getText();
totalStr = totalStr+str;
jta.setText(totalStr);
jtf.setText("");
}
});
}
public static void main(String[] args) {
new AddText();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询