⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buttonactiondemo.java

📁 这是一个用java编写的关于GUI应用编程的简单的样例
💻 JAVA
字号:
package chap13.demo;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2008-3-10
 * Time: 23:12:29
 * File ButtonActionDemo.java
 */
public class ButtonActionDemo extends JFrame {
    JTextArea txtInfo=new JTextArea(5,40);

    public ButtonActionDemo(String title) throws HeadlessException {
        super(title);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JScrollPane scrollPane = new JScrollPane(txtInfo);

        this.add(scrollPane,BorderLayout.NORTH);
        JPanel panel=new JPanel();
        this.add(panel,BorderLayout.CENTER);
        JButton btnYou=new JButton(new YouAction("You"));
        panel.add(btnYou);
        this.pack();
        this.setVisible(true);

    }
    private void display(String actionDescription,
                                 ActionEvent e){
        txtInfo.append("info from "+e.getSource()+","+actionDescription+"\r\n");
    }
    class YouAction extends AbstractAction{

        public YouAction(String name) {
            super(name);
        }
        public void actionPerformed(ActionEvent e) {
            display("Action for you uutton",e);
        }
    }

    public static void main(String[] args){
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                ButtonActionDemo demo=new ButtonActionDemo("ActionDemo");
                
            }
        });

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -