学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
发新话题
打印

关于ActionEvent问题

关于ActionEvent问题

package aaa;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class demo1 extends JFrame {
       JTextArea Area = new JTextArea(6,40);
       JTextField tf1= new JTextField(15);
       JTextField tf2=new JTextField(15);
    public demo1(){
        add(Area);
        add(new JLabel("name"));
        add(tf1);
        add(new JLabel("身份证"));
        add(tf2);
        tf1.addActionListener(new ActionLis());
        tf2.addActionListener(new ActionLis());
        
    }
    class ActionLis implements ActionListener{
        public void actionperformed(ActionEvent e){
            if(e.getSource()==tf1)
                Area.append("姓名"+tf1.getText()+"/n");
            else
                Area.append("身份证"+tf1.getText()+"/n");
        }
    }
    public static void main(String arg[]){
        
        demo1 d=new demo1();
        d.setTitle("aaa");
        FlowLayout f=new FlowLayout();//逐行布局
        d.setLayout(f);
        Dimension ScreenSize=Toolkit.getDefaultToolkit().getScreenSize(); /*获取屏幕大小*/
        Dimension frameSize=d.getSize();/*表单大小*/
        d.setLocation((ScreenSize.width-frameSize.width)/2,(ScreenSize.height-frameSize.height)/2);/*居中显示*/
        d.setVisible(true);
        d.setSize(300,100);
        
        
    }
用eclipse运行的时候 为什么ActionLis这个地方有错误,哪位高手指点一下谢谢

TOP

" public void actionperformed(ActionEvent e){"
方法覆盖 P 字母大写,
public void actionPerformed(ActionEvent e){

TOP

另外你的窗体大小没设置!

TOP

我觉得把什么容器,布局等放在demo1中比较好,看起来整洁

TOP

发新话题