我也是初学者,不过我建议你用swing的组件,下面是我写得代码import java.awt.event.*; 
import java.awt.*; 
import javax.swing.*;public class A extends JApplet{
JTextField text;
JButton btn; 
public void init() {
text = new JTextField(10); 
btn = new JButton("确定"); 
getContentPane().setLayout(new FlowLayout());
getContentPane().add(text);
getContentPane().add(btn);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btn) {
text.setText("刚点击了:" + btn.getText()); 
}
}
}); 
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JApplet a = new A();
frame.getContentPane().add(a);
frame.setSize(200, 100);
a.init();
a.start();
frame.setLocationRelativeTo(null);//居屏幕中央显示
frame.setVisible(true);
}

解决方案 »

  1.   

    我编译了一下我的程序,提示错误,信息如下:
    a.java:4: A is not abstract and does not override abstract method actionPerforme
    d(java.awt.event.ActionEvent) in java.awt.event.ActionListener
    public class A extends Applet implements ActionListener
           ^
    怎么修改我的那个啊?谢谢了.
    楼上的源码我抄下了,下线了研究研究,呵呵,谢谢你的帮助.
      

  2.   

    public void actionPerformer(ActionEvent e)
    这是你写的,我估计是打字错误,没有重载actionPerformed(ActionEvent e)方法,当然报错
      

  3.   

    这个例子是一般初学JAVA常用的例子,可以多看看书
      

  4.   

    继承ActionListener接口要实现actionPerformeed方法的,
    public void actionPerformed(ActionEvent e){}
    楼主些错了吧,我调试过了,成功!