import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class Test89 {
public static void main(String args[]) {
//Jframe
JFrame f = new JFrame();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
final TextField text = new TextField(30);
Button btn = new Button("点击");
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
text.setText("你好");;
}
});
f.setTitle("例子");
f.setLayout(new FlowLayout());
f.add(text);
f.add(btn);
f.setBackground(Color.WHITE);
f.setSize(280, 100);
f.setLocationRelativeTo(f);//position center.
f.setVisible(true);//show.
}
}
是使用java swing,还是android的技术,不过都大同小异,他已经提供了监听的函数,只需要直接调用就可以了.遇到问题可以贴出来