回 帖 发 新 帖 刷新版面

主题:help me !!!

import java.awt.*;
import java.awt.event.*;

public class awt extends Frame{
    private final String names[]={"one","two","three","four","five","six"};
    private Button[] buttons=new Button[6];
    private boolean flag=true;
    final GridLayout layout1=new GridLayout(2,3,5,10);
    final GridLayout layout2=new GridLayout(3,2);
    
    public awt(String title) {
        super(title);
        setLayout();
        ActionListener listener=new ActionListener(){
            setLayout();                             //这里错啦 why?
            awt.this.validate();                     //这里错啦 why?
        };
        for(int i=0;i<buttons.length;i++){
            buttons[i]=new Button(names[i]);
            buttons[i].addActionlistener(listener);
            add(buttons[i]);
        }
        
        setSize(250,250);
        setVisible(true);
        
    }
    private void setLayout(){
        if(flag)
            setLayout(layout1);
        else 
            setLayout(layout2);
        flag=!flag;
    }
    
    
    public static void main(String[] args) {
        new awt("java");
        
        
        
        
    }
    
}[em10][em10][em10]ffff

回复列表 (共2个回复)

沙发

ActionListener是个接口,不是一个类

板凳

楼上正解

我来回复

您尚未登录,请登录后再回复。点此登录或注册