黑马程序员_建立一个文本框 一个文本区域 一个按钮 文本框只能输入数字 并通过按钮 转换到文本区域

时间:2022-12-08 21:53:04

---------------------- <a href="http://edu.csdn.net/heima" target="blank">android培训</a>、<a href="http://edu.csdn.net/heima" target="blank">java培训</a>、期待与您交流! ----------------------
import java.awt.*;

import java.awt.event.*;
class practice26 
{
private Frame frame;
private TextField tf;
private Button b;
private TextArea ta;
practice26()
{
ini();
}
public void ini()
{
frame=new Frame();
frame.setBounds(200,100,500,400);
frame.setLayout(new FlowLayout());
tf=new TextField(30);
ta=new TextArea(5,40);
b=new Button("弹弹弹");
frame.add(tf);
frame.add(b);
frame.add(ta);
method();
frame.setVisible(true);
}
public void method()
{
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}});
b.addActionListener(new ActionListener(){
Dialog d;
public void actionPerformed(ActionEvent e)
{
if(tf.getText().matches("\\d+"))
ta.setText(tf.getText());
else
{
d=new Dialog(frame);
Label lb=new Label("不是数字");
Button bu=new Button("确定");
d.setBounds(300,200,200,100);
d.setLayout(new FlowLayout());
d.add(lb);
d.add(bu);
d.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
d.setVisible(false);
}});
bu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ d.setVisible(false);
}
});
d.setVisible(true);
}
}});}
public static void main(String[] args) 
{
new practice26();
}

}


---------------------- <a href="http://edu.csdn.net/heima" target="blank">android培训</a>、<a href="http://edu.csdn.net/heima" target="blank">java培训</a>、期待与您交流! ----------------------