frame设置文本框

来源:互联网 发布:剪刀手爱德华 知乎 编辑:程序博客网 时间:2024/06/12 01:48


public static void main(String[] args) {// 创建窗体对象Frame f = new Frame("数据转移");// 设置窗体属性和布局f.setBounds(400, 200, 400, 300);f.setLayout(new FlowLayout());// 创建文本框final TextField tf = new TextField(20);// 创建按钮Button bu = new Button("数据转移");// 创建文本域final TextArea ta = new TextArea(10, 40);// 把组件添加到窗体f.add(tf);f.add(bu);f.add(ta);// 设置窗体关闭f.addWindowListener(new WindowAdapter() {@Overridepublic void windowClosing(WindowEvent e) {System.exit(0);}});// 对按钮添加事件bu.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// 获取文本框的值String tf_str = tf.getText().trim();// 清空数据tf.setText("");// 设置给文本域// ta.setText(tf_str);// 追加和换行ta.append(tf_str + "\r\n");//获取光标tf.requestFocus();}});// 设置窗体显示f.setVisible(true);}



0 0
原创粉丝点击