GUI:textActionEvent


import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class textActionEvent {
    public static void main(String[] args) {

        Frame frame = new Frame();
        Button button = new Button();

        MyActionListener myActionListener = new MyActionListener();
        //需要构造MyActionListener,来传值
        button.addActionListener(myActionListener);
        frame.add(button, BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);
    }


    private static void windowClose (Frame frame){
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }

        });
    }

    static class MyActionListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            //点击按钮触发的事件
            System.out.println("清宵是大美女");
        }
    }
}

你可能感兴趣的:(Gui,java,开发语言)