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

📄 listenertest.java~7~

📁 java GUI用户界面程序
💻 JAVA~7~
字号:
package chapter7.event;

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

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: 太阳微电脑有限公司</p>
 *
 * @author 陈雄华
 * @version 1.0
 */
public class ListenerTest
    extends JFrame
{
    public static void main(String[] args)
    {
        ListenerTest listenertest = new ListenerTest();
        MyActionListener listener = new MyActionListener();
        JButton jb1 = new JButton("hello");
        jb1.addActionListener(listener);
        JButton jb2 = new JButton("well");
        jb2.addActionListener(listener);
        listenertest.getContentPane().add(jb1);
        listenertest.getContentPane().add(jb2);
        listenertest.setSize(200, 200);
        listenertest.show();
    }
}

class MyActionListener
    implements ActionListener
{
    public void actionPerformed(ActionEvent e)
    {
        JButton jb = (JButton)e.getSource();
        if (jb.getText().equalsIgnoreCase("hello"))
        {
            JOptionPane.showConfirmDialog(null, "hello", "hello",
                                      JOptionPane.CLOSED_OPTION);
        }
        else
        {
            JOptionPane.showConfirmDialog(null, "well", "well",
                                      JOptionPane.CLOSED_OPTION);
        }

    }
}

⌨️ 快捷键说明

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